Skip to content

Commit 04bf83e

Browse files
committed
Fix basi matcher test & doc
1 parent 9223597 commit 04bf83e

3 files changed

Lines changed: 56 additions & 56 deletions

File tree

docs/API.md

Lines changed: 51 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -907,60 +907,56 @@ await expect(elem).toHaveElementClass(/Container/i)
907907
In addition to the WebdriverIO matchers, `expect-webdriverio` also provides basic matchers from Jest's [expect](https://jestjs.io/docs/expect) library.
908908

909909
```ts
910-
describe('Expect matchers', () => {
911-
test('Basic matchers', async () => {
912-
// Equality
913-
expect(2 + 2).toBe(4);
914-
expect({a: 1}).toEqual({a: 1});
915-
expect([1, 2, 3]).toStrictEqual([1, 2, 3]);
916-
expect(2 + 2).not.toBe(5);
917-
918-
// Truthiness
919-
expect(null).toBeNull();
920-
expect(undefined).toBeUndefined();
921-
expect(0).toBeFalsy();
922-
expect(1).toBeTruthy();
923-
expect(NaN).toBeNaN();
924-
925-
// Numbers
926-
expect(4).toBeGreaterThan(3);
927-
expect(4).toBeGreaterThanOrEqual(4);
928-
expect(4).toBeLessThan(5);
929-
expect(4).toBeLessThanOrEqual(4);
930-
expect(0.2 + 0.1).toBeCloseTo(0.3, 5);
931-
932-
// Strings
933-
expect('team').toMatch(/team/);
934-
expect('Christoph').toContain('stop');
935-
936-
// Arrays and iterables
937-
expect([1, 2, 3]).toContain(2);
938-
expect([{a: 1}, {b: 2}]).toContainEqual({a: 1});
939-
expect([1, 2, 3]).toHaveLength(3);
940-
941-
// Objects
942-
expect({a: 1, b: 2}).toHaveProperty('a');
943-
expect({a: {b: 2}}).toHaveProperty('a.b', 2);
944-
945-
// Errors
946-
expect(() => { throw new Error('error!') }).toThrow('error!');
947-
expect(() => { throw new TypeError('wrong type') }).toThrow(TypeError);
948-
949-
// Asymmetric matchers
950-
expect({foo: 'bar', baz: 1}).toEqual(expect.objectContaining({foo: expect.any(String)}));
951-
expect([1, 2, 3]).toEqual(expect.arrayContaining([2]));
952-
expect('abc').toEqual(expect.stringContaining('b'));
953-
expect('abc').toEqual(expect.stringMatching(/b/));
954-
expect(123).toEqual(expect.any(Number));
955-
956-
// Others
957-
expect(new Set([1, 2, 3])).toContain(2);
958-
959-
// .resolves / .rejects (async)
960-
await expect(Promise.resolve(42)).resolves.toBe(42);
961-
await expect(Promise.reject(new Error('fail'))).rejects.toThrow('fail');
962-
});
963-
});
910+
// Equality
911+
expect(2 + 2).toBe(4);
912+
expect({a: 1}).toEqual({a: 1});
913+
expect([1, 2, 3]).toStrictEqual([1, 2, 3]);
914+
expect(2 + 2).not.toBe(5);
915+
916+
// Truthiness
917+
expect(null).toBeNull();
918+
expect(undefined).toBeUndefined();
919+
expect(0).toBeFalsy();
920+
expect(1).toBeTruthy();
921+
expect(NaN).toBeNaN();
922+
923+
// Numbers
924+
expect(4).toBeGreaterThan(3);
925+
expect(4).toBeGreaterThanOrEqual(4);
926+
expect(4).toBeLessThan(5);
927+
expect(4).toBeLessThanOrEqual(4);
928+
expect(0.2 + 0.1).toBeCloseTo(0.3, 5);
929+
930+
// Strings
931+
expect('team').toMatch(/team/);
932+
expect('Christoph').toContain('stop');
933+
934+
// Arrays and iterables
935+
expect([1, 2, 3]).toContain(2);
936+
expect([{a: 1}, {b: 2}]).toContainEqual({a: 1});
937+
expect([1, 2, 3]).toHaveLength(3);
938+
939+
// Objects
940+
expect({a: 1, b: 2}).toHaveProperty('a');
941+
expect({a: {b: 2}}).toHaveProperty('a.b', 2);
942+
943+
// Errors
944+
expect(() => { throw new Error('error!') }).toThrow('error!');
945+
expect(() => { throw new TypeError('wrong type') }).toThrow(TypeError);
946+
947+
// Asymmetric matchers
948+
expect({foo: 'bar', baz: 1}).toEqual(expect.objectContaining({foo: expect.any(String)}));
949+
expect([1, 2, 3]).toEqual(expect.arrayContaining([2]));
950+
expect('abc').toEqual(expect.stringContaining('b'));
951+
expect('abc').toEqual(expect.stringMatching(/b/));
952+
expect(123).toEqual(expect.any(Number));
953+
954+
// Others
955+
expect(new Set([1, 2, 3])).toContain(2);
956+
957+
// .resolves / .rejects (async)
958+
await expect(Promise.resolve(42)).resolves.toBe(42);
959+
await expect(Promise.reject(new Error('fail'))).rejects.toThrow('fail');
964960
```
965961

966962
### Jasmine
@@ -1013,7 +1009,7 @@ await expect(browser).toHaveTitle(expect.not.stringContaining('some title'))
10131009
Under `@wdio/jasmine-framework`, Jasmine asymmetric matchers now works with WebdriverIO matchers and the global import
10141010

10151011
```ts
1016-
// Jasmine stringContaining works just lik expect one's
1012+
// Jasmine stringContaining works just like expect one's
10171013
await expect(browser).toHaveTitle(jasmine.stringContaining('some title'))
10181014
await expect(browser).toHaveTitle(expect.stringContaining('some title'))
10191015
```

playgrounds/mocha/test/specs/basic-matchers.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ describe('Basic Expect Matchers', () => {
66
})
77

88
describe('Expect matchers', () => {
9-
test('Basic matchers', async () => {
9+
it('Basic matchers', async () => {
1010
// Equality
1111
expect(2 + 2).toBe(4);
1212
expect({a: 1}).toEqual({a: 1});

playgrounds/mocha/wdio.conf.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ export const config: WebdriverIO.Config = {
1818
//
1919
specs: [
2020
'./test/specs/**/*.test.ts',
21+
//'./test/specs/**/basic-matchers.test.ts',
2122
//'./test/specs/**/visual-snapshot.test.ts'
23+
//'./test/specs/**/soft-expect.test.ts',
24+
//'./test/specs/**/snapshot.test.ts'
25+
//'./test/specs/**/wdio-matchers.test.ts'
2226
],
2327

2428
//

0 commit comments

Comments
 (0)