Skip to content

Commit

Permalink
very basic tests for the checkDef method
Browse files Browse the repository at this point in the history
  • Loading branch information
bago committed May 31, 2022
1 parent a067276 commit 9d7dd19
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion spec/converter-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('Template converter', function() {

beforeAll(function() {
mockery.registerMock('jquery', require('cheerio').load('<html />'));
mockery.registerAllowables(['fs', '../src/js/converter/declarations.js', '../src/js/converter/model.js', '../src/js/converter/parser.js', 'console', './utils.js', './domutils.js', 'console', '../node_modules/mensch', './lib/lexer', './lib/parser', './lib/stringify', './debug', 'jsep', './declarations.js', 'mensch/lib/parser.js', 'mensch/lib/parser.js', './lexer', './stylesheet.js', './model.js']);
mockery.registerAllowables(['fs', '../src/js/converter/checkdefs.js', '../src/js/converter/declarations.js', '../src/js/converter/model.js', '../src/js/converter/parser.js', 'console', './utils.js', './domutils.js', 'console', '../node_modules/mensch', './lib/lexer', './lib/parser', './lib/stringify', './debug', 'jsep', './declarations.js', 'mensch/lib/parser.js', 'mensch/lib/parser.js', './lexer', './stylesheet.js', './model.js']);
mockery.enable();

_parseTemplate = function(html) {
Expand Down Expand Up @@ -249,6 +249,55 @@ describe('Template converter', function() {

});

it('should detect missing default values', function() {
var parseData = _parseTemplate('<replacedhtml><replacedhead>\
<style type="text/css">\
@supports -ko-blockdefs {\
text { label: Paragraph; widget: text }\
url { label: Link; widget: url }\
template { label: Page; }\
}\
</style>\
</replacedhead><repleacedbody><div style="something: 23; -ko-something: @[myUrl !== \'\' ? \'foo\' : \'bar\']" /><div data-ko-container="main"></div></replacedbody></replacedhtml>');

var checkDefs = require('../src/js/converter/checkdefs.js');
var ok = checkDefs(parseData.templateDef._defs);
expect(ok).toBe(false);
});

it('should detect data-ko-properties default value declarations', function() {
var parseData = _parseTemplate('<replacedhtml><replacedhead>\
<style type="text/css">\
@supports -ko-blockdefs {\
text { label: Paragraph; widget: text }\
url { label: Link; widget: url }\
template { label: Page; }\
}\
</style>\
</replacedhead><repleacedbody><div data-ko-properties="myUrl=\'\'" style="something: 23; -ko-something: @[myUrl !== \'\' ? \'foo\' : \'bar\']" /><div data-ko-container="main"></div></replacedbody></replacedhtml>');

var checkDefs = require('../src/js/converter/checkdefs.js');
var ok = checkDefs(parseData.templateDef._defs);

expect(ok).toBe(true);
});

it('should detect -ko-blockdefs default value declarations in properties', function() {
var parseData = _parseTemplate('<replacedhtml><replacedhead>\
<style type="text/css">\
@supports -ko-blockdefs {\
text { label: Paragraph; widget: text }\
url { label: Link; widget: url }\
template { label: Page; properties: myUrl=\'\' }\
}\
</style>\
</replacedhead><repleacedbody><div style="something: 23; -ko-something: @[myUrl !== \'\' ? \'foo\' : \'bar\']" /><div data-ko-container="main"></div></replacedbody></replacedhtml>');

var checkDefs = require('../src/js/converter/checkdefs.js');
var ok = checkDefs(parseData.templateDef._defs);
expect(ok).toBe(true);
});

afterAll(function() {
mockery.disable();
mockery.deregisterAll();
Expand Down

0 comments on commit 9d7dd19

Please sign in to comment.