UNPKG

1.9 kBJavaScriptView Raw
1var describeIt = require('..');
2var fooFilename = __dirname + '/foo.js';
3
4describeIt(fooFilename, 'getFoo()', function (getFn) {
5 it('has function argument', function () {
6 la(typeof getFn === 'function');
7 });
8
9 it('returns actual function', function () {
10 var fn = getFn();
11 la(typeof fn === 'function');
12 });
13
14 it('works', function () {
15 var getFoo = getFn();
16 la(getFoo() === 'foo');
17 });
18});
19
20describeIt(fooFilename, 'getFoo()', function (getFn) {
21 it('returns "foo"', function () {
22 var getFoo = getFn();
23 la(getFoo() === 'foo');
24 });
25});
26
27describe('extracting value before each unit test', function () {
28 describeIt(fooFilename, 'getFoo()', function (getFn) {
29 var getFoo;
30
31 beforeEach(function () {
32 getFoo = getFn();
33 });
34
35 it('returns "foo"', function () {
36 la(getFoo() === 'foo');
37 });
38
39 afterEach(function () {
40 la(getFn() === getFoo);
41 });
42 });
43});
44
45describe('storing extracted value on the context object', function () {
46 describeIt(fooFilename, 'getFoo()', function (getFn) {
47 beforeEach(function () {
48 this.getFoo = getFn();
49 });
50
51 it('returns "foo"', function () {
52 la(this.getFoo() === 'foo');
53 });
54 });
55});
56
57describe('assign shortcut', function () {
58 describeIt(fooFilename, 'getFoo()', function (getFn) {
59 function assign(property, get) {
60 this[property] = get();
61 return this[property];
62 }
63
64 beforeEach(assign.bind(this.ctx, 'getFoo', getFn));
65
66 it('returns "foo"', function () {
67 la(this.getFoo() === 'foo');
68 });
69 });
70});
71
72describe('automatic assign to property', function () {
73 describeIt(fooFilename, 'getFoo()', function () {
74 it('assigns getFoo to property', function () {
75 la(typeof this.getFoo === 'function', 'has getFoo function');
76 });
77
78 it('returns "foo"', function () {
79 la(this.getFoo() === 'foo');
80 });
81 });
82});