-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtest.js
40 lines (37 loc) · 1.28 KB
/
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
'use strict';
import chai, {expect} from 'chai';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import renderIf from './renderIf';
chai.use(sinonChai);
describe('renderIf', () => {
it('should return a function', () => {
expect(typeof renderIf()).to.be.eql('function');
});
describe('non-lazy', () => {
it('should return the element when the predicate passes', () => {
expect(renderIf(true)('foobar')).to.be.eql('foobar');
});
it('should not return the element when the predicate fails', () => {
expect(renderIf(false)('foobar')).to.be.eql(null);
});
});
describe('lazy', () => {
it('should return the result of the thunk when the predicate passes', () => {
expect(renderIf(true)(() => 'foobar')).to.be.eql('foobar');
});
it('should not return the result of the thunk when the predicate fails', () => {
expect(renderIf(false)(() => 'foobar')).to.be.eql(null);
});
it ('should call the thunk when the predicate passes', () => {
var spy = sinon.spy();
renderIf(true)(spy);
expect(spy).to.have.been.called;
});
it ('should not call the thunk when the predicate fails', () => {
var spy = sinon.spy();
renderIf(false)(spy);
expect(spy).not.to.have.been.called;
});
});
});