Skip to content

Commit 2088418

Browse files
committed
Fixed handling of spec filters that are RegExp instances
Fixes #215
1 parent 0a8ce13 commit 2088418

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

lib/jasmine.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ class Jasmine extends RunnerBase {
215215
}
216216

217217
if (filter) {
218-
if (typeof filter === 'string') {
218+
if (typeof filter === 'string' || filter instanceof RegExp) {
219219
this.env.configure({
220220
specFilter: regexSpecFilter(filter)
221221
});

spec/filters/regex_spec_filter_spec.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,18 @@ describe("regexSpecFilter", function() {
99
});
1010

1111
it("should match the provided string", function() {
12-
const specFilter = regexSpecFilter("foo");
12+
const specFilter = regexSpecFilter("foo?");
1313

1414
expect(specFilter({ getFullName: () => "foo"})).toBe(true);
15+
expect(specFilter({ getFullName: () => "fo"})).toBe(true);
16+
expect(specFilter({ getFullName: () => "bar"})).toBe(false);
17+
});
18+
19+
it("should match the provided regex", function() {
20+
const specFilter = regexSpecFilter(/foo?/);
21+
22+
expect(specFilter({ getFullName: () => "foo"})).toBe(true);
23+
expect(specFilter({ getFullName: () => "fo"})).toBe(true);
1524
expect(specFilter({ getFullName: () => "bar"})).toBe(false);
1625
});
1726

spec/jasmine_spec.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,28 @@ describe('Jasmine', function() {
262262
});
263263
});
264264

265+
describe('When a filter regex is provided', function () {
266+
it('installs a matching spec filter', async function () {
267+
await this.execute({
268+
executeArgs: [['spec/fixtures/example/*spec.js'], /interesting spec/]
269+
});
270+
271+
expect(specFilter).toBeTruthy();
272+
const matchingSpec = {
273+
getFullName() {
274+
return 'this is an interesting spec that should match';
275+
}
276+
};
277+
const nonMatchingSpec = {
278+
getFullName() {
279+
return 'but this one is not';
280+
}
281+
};
282+
expect(specFilter(matchingSpec)).toBeTrue();
283+
expect(specFilter(nonMatchingSpec)).toBeFalse();
284+
});
285+
});
286+
265287
describe('When a path filter specification is provided', function () {
266288
it('installs a matching spec filter', async function () {
267289
await this.execute({

0 commit comments

Comments
 (0)