/
single.jsx
44 lines (39 loc) · 1.16 KB
/
single.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import React from 'react';
import { expect } from 'chai';
import {
sym,
} from 'enzyme/build/Utils';
export default function describeSingle({
Wrap,
}) {
describe('#single()', () => {
it('throws if run on multiple nodes', () => {
const wrapper = Wrap(<div><i /><i /></div>).children();
expect(wrapper).to.have.lengthOf(2);
expect(() => wrapper.single('name!')).to.throw(
Error,
'Method “name!” is meant to be run on 1 node. 2 found instead.',
);
});
it('throws if run on zero nodes', () => {
const wrapper = Wrap(<div />).children();
expect(wrapper).to.have.lengthOf(0);
expect(() => wrapper.single('name!')).to.throw(
Error,
'Method “name!” is meant to be run on 1 node. 0 found instead.',
);
});
it('works with a name', () => {
const wrapper = Wrap(<div />);
wrapper.single('foo', (node) => {
expect(node).to.equal(wrapper[sym('__node__')]);
});
});
it('works without a name', () => {
const wrapper = Wrap(<div />);
wrapper.single((node) => {
expect(node).to.equal(wrapper[sym('__node__')]);
});
});
});
}