Skip to content
Permalink
Browse files

test: add tests to cover that correct arguments are passed to Compone…

…nt.compose() and Component.preprocess()
  • Loading branch information...
thesephist committed May 15, 2019
1 parent 9ea5ea3 commit 26f8f37ab3ac480b8d671957db418e07fad8883a
Showing with 33 additions and 1 deletion.
  1. +1 −1 src/torus.js
  2. +32 −0 test/torus.js
@@ -562,7 +562,7 @@ class Component {
//> `#preprocess()` is an API on the component to allow us to extend `Component` to give
// it additional capabilities idiomatically. It consumes the result of `#compose()` and
// returns JDOM to be used to actually render the component. See `Styled()` for a
// usage example -- it fills similar use cases as React's render props or HOCs.
// usage example.
preprocess(jdom) {
return jdom;
}
@@ -741,6 +741,38 @@ describe('Component', () => {
}).to.throw(Error);
});

it('should pass argument 0 (data) to #compose()', () => {
const testData = 'some_test_data';
let testDataTarget = 'wrong_data';
class Test extends Component {
compose(data) {
testDataTarget = data;
return null;
}
}
const t = new Test();
t.render(testData);

testDataTarget.should.equal(testData);
});

it('should pass jdom and argument 0 (data) to #preprocess()', () => {
const testData = 'some_test_data';
let testDataTarget = 'wrong_data';
let testJDOM = null;
class Test extends Component {
preprocess(jdom, data) {
testDataTarget = data;
testJDOM = jdom;
return null;
}
}
const t = new Test();
t.render(testData);

expect(t.jdom).to.equal(testJDOM);
testDataTarget.should.equal(testData);
});

});

0 comments on commit 26f8f37

Please sign in to comment.
You can’t perform that action at this time.