mirror of
https://github.com/pezkuwichain/pezkuwi-dev.git
synced 2026-10-27 05:49:48 +00:00
dev-test: DOM node hierarchy in the browser env; expect().toContain
The browser env exposed the HTML*Element constructors but not the classes above them, so a library checking `instanceof Element` (as react-tooltip does on every hover) threw "Element is not defined". Node, Element, Document, DocumentFragment, Text, ShadowRoot and SVGElement now come from JSDOM. expect().toContain and .not.toContain were stubs. A string contains a substring; any other iterable contains the item itself, not a deep-equal copy, as in jest.
This commit is contained in:
1 parent
0cd4f12cfb
commit
4e3bf04010
4 files changed
+82
-1
No files matched your search
+24
@@ -255,4 +255,28 @@ describe('expect', () => {
|
||||
expect(() => expect([1, 2]).not.toEqual(expect.arrayContaining([2]))).toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('.toContain', () => {
|
||||
it('finds a substring in a string', () => {
|
||||
expect('voter-alice').toContain('alice');
|
||||
expect(() => expect('voter-alice').toContain('bob')).toThrow();
|
||||
});
|
||||
|
||||
it('finds the item itself in an array or other iterable', () => {
|
||||
const item = { a: 1 };
|
||||
|
||||
expect([1, item]).toContain(item);
|
||||
expect(new Set(['a'])).toContain('a');
|
||||
expect(() => expect([{ a: 1 }]).toContain({ a: 1 })).toThrow();
|
||||
});
|
||||
|
||||
it('rejects a value that is neither a string nor an iterable', () => {
|
||||
expect(() => expect(123).toContain(1)).toThrow();
|
||||
});
|
||||
|
||||
it('supports .not', () => {
|
||||
expect('voter-alice').not.toContain('bob');
|
||||
expect(() => expect([1, 2]).not.toContain(2)).toThrow();
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user