Skip to content

Commit

Permalink
Implement exportTheme() method.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjeffburke committed Dec 29, 2019
1 parent a1e2c89 commit 4e7cdc2
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/createTopLevelExpect.js
Expand Up @@ -1604,6 +1604,10 @@ expectPrototype.child = function() {
parent.addAssertion(testDescription, handler, childExpect);
return this;
};
childExpect.exportTheme = function(...args) {
parent.installTheme(...args);
return this;
};
childExpect.exportType = function(type) {
if (childExpect.getType(type.name) !== type) {
childExpect.addType(type);
Expand Down
56 changes: 56 additions & 0 deletions test/api/exportTheme.spec.js
@@ -0,0 +1,56 @@
/* global expect */
describe('exportTheme', () => {
let parentExpect;
let childExpect;

beforeEach(() => {
parentExpect = expect.clone();
childExpect = parentExpect.child();
});

it('is chainable', () => {
childExpect
.exportTheme('html', {
styles: {
firstStyle: '#E3E3E3'
}
})
.exportTheme('html', {
styles: {
secondStyle: '#3E3E3E'
}
});

expect(parentExpect.output.theme('html'), 'to satisfy', {
styles: {
firstStyle: '#E3E3E3',
secondStyle: '#3E3E3E'
}
});
});

it('makes the style available to the parent expect', () => {
childExpect.exportTheme('html', {
styles: {
error: ['#000000', 'italic']
}
});

expect(
parentExpect
.createOutput('html')
.error('yadda')
.toString(),
'to contain',
'<span style="color: #000000; font-style: italic">yadda</span>'
);
});

it('does not make the style available to a parent parent expect', () => {
childExpect.child().exportTheme('html', {styles: {'fancyQuotes': '#333333'}});

expect(expect.output.theme('html'), 'to satisfy', {
styles: expect.it('not to have property', 'fancyQuotes')
});
});
});

0 comments on commit 4e7cdc2

Please sign in to comment.