-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.spec.js
53 lines (42 loc) · 1.44 KB
/
index.spec.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
50
51
52
53
import test from 'ava';
import Documentation from 'react-docgen/dist/Documentation';
import { statement } from '../tests/utils';
import importsHandler from './index';
let documentation = null;
test.beforeEach(() => {
documentation = new Documentation();
});
test('For files that contain no imported resources', (t) => {
const definition = statement(`
class Foo {
render() { return <button />; }
}
`);
importsHandler(documentation, definition);
const actual = documentation.get('imports');
const expected = [];
t.deepEqual(actual, expected, 'it should return an empty array');
});
test('For files using ES2015 import syntax', (t) => {
const definition = statement(`
import Button from './button';
import * as React from 'react';
import { a, b as c } from '../foo';
`);
importsHandler(documentation, definition);
const actual = documentation.get('imports');
const expected = ['./button', 'react', '../foo'];
t.deepEqual(actual, expected,
'it should find the sources for all import statements');
});
test('For files using CommonJS require function calls', (t) => {
const definition = statement(`
var Button = require('./button');
var React = require('re' + 'act');
`);
importsHandler(documentation, definition);
const actual = documentation.get('imports');
const expected = ['./button'];
t.deepEqual(actual, expected,
'it should find the sources for all static require calls');
});