-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
test.js
49 lines (38 loc) · 986 Bytes
/
test.js
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
45
46
47
48
49
import test from 'ava';
import importLazy from '.';
const importLazyBound = importLazy(require);
test('main', t => {
const foo = importLazyBound('./fixtures/foo');
t.is(foo(), 'foo');
const baz = importLazyBound('./fixtures/baz');
t.is(baz('j', 's'), 'bazjs');
});
test('lazy', t => {
importLazyBound('./fixtures/fail');
t.pass();
});
test('props', t => {
const object = importLazyBound('./fixtures/foo.bar.js');
t.is(object.foo(), 'foo');
t.is(object.bar('j', 's'), 'barjs');
t.is(object.baz, 'baz');
});
test('class', t => {
const Class = importLazyBound('./fixtures/class.js');
let instance;
t.notThrows(() => {
instance = new Class('42');
});
t.true(instance instanceof Class);
t.is(instance.message, '42');
});
test('destructuring makes it eager', t => {
let invoked = false;
const fakeRequire = () => {
invoked = true;
return {foo: 'bar'};
};
const {foo} = importLazy(fakeRequire)('fake-module-name');
t.is(foo, 'bar');
t.true(invoked);
});