1 | import externalToFn from './external-to-fn';
|
2 |
|
3 | describe('#externalToFn', () => {
|
4 | describe('when passed a function', () => {
|
5 | it('returns the same function', () => {
|
6 | const fn = () => true;
|
7 | expect(externalToFn(fn)).toBe(fn);
|
8 | });
|
9 | });
|
10 |
|
11 | describe('when passed an array of module names', () => {
|
12 | it('returns a predicate returning true if passed one of the module names', () => {
|
13 | const modules = ['lodash', 'lodash-es'];
|
14 | const fn = externalToFn(modules);
|
15 |
|
16 | expect(fn('lodash')).toBe(true);
|
17 | expect(fn('lodash-')).toBe(false);
|
18 | expect(fn('lodash-es')).toBe(true);
|
19 | expect(fn('lodash/map')).toBe(false);
|
20 | });
|
21 | });
|
22 |
|
23 | describe('when passed anything but a function or array', () => {
|
24 | it('throws an error', () => {
|
25 | expect(() => externalToFn('string')).toThrow();
|
26 | });
|
27 | });
|
28 | });
|