Skip to content

Commit

Permalink
Bug fix for removing jQuery dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
kmalakoff committed Feb 4, 2017
1 parent f2f214d commit b7db9d2
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 23 deletions.
2 changes: 2 additions & 0 deletions config/karma/base-config.coffee
Expand Up @@ -13,3 +13,5 @@ module.exports =
logLevel: 'INFO'
browsers: ['PhantomJS'] # ['Firefox', 'Chrome', 'Safari']
singleRun: true
# browsers: ['Chrome']
# singleRun: false
4 changes: 2 additions & 2 deletions config/test_groups.coffee
Expand Up @@ -14,7 +14,7 @@ KNOCKBACK =
core_stack: ['./knockback-core-stack.js']

REQUIRED_DEPENDENCIES =
backbone_underscore_latest: (resolveModule(module_name) for module_name in ['underscore', 'backbone', 'knockout'])
backbone_underscore_latest: (resolveModule(module_name) for module_name in ['jquery', 'underscore', 'backbone', 'knockout'])
backbone_underscore_legacy: ['./vendor/underscore-1.1.7.js', './vendor/backbone-0.5.1.js', './vendor/knockout-2.1.0.js']
backbone_lodash_latest: (resolveModule(module_name) for module_name in ['lodash', 'backbone', 'knockout'])
backbone_lodash_legacy: ['./vendor/lodash-0.3.2.js', './vendor/backbone-0.5.1.js', './vendor/knockout-2.1.0.js']
Expand All @@ -34,7 +34,7 @@ TEST_GROUPS.browser_globals = []
for library_name, library_files of KNOCKBACK when (library_name.indexOf('browser_globals') >= 0 and library_name.indexOf('stack') < 0)
for dep_name, dep_files of REQUIRED_DEPENDENCIES
if dep_name.indexOf('backbone') >= 0 # Backbone
TEST_GROUPS.browser_globals.push({name: "#{dep_name}_#{library_name}", files: _.flatten([dep_files, library_files, LOCALIZATION_DEPENCIES, resolveModule('backbone-modelref'), './test/spec/core/**/*.tests.coffee', './test/spec/plugins/**/*.tests.coffee'])})
TEST_GROUPS.browser_globals.push({name: "#{dep_name}_#{library_name}", files: _.flatten([dep_files, library_files, LOCALIZATION_DEPENCIES, resolveModule('backbone-modelref'), './test/spec/core/**/*.tests.coffee', './test/spec/plugins/**/*.tests.coffee', './test/spec/issues/**/*.tests.coffee'])})
else # Parse
TEST_GROUPS.browser_globals.push({name: "#{dep_name}_#{library_name}", files: _.flatten([dep_files, library_files, LOCALIZATION_DEPENCIES, './test/spec/core/**/*.tests.coffee', './test/spec/plugins/**/*.tests.coffee'])})

Expand Down
6 changes: 3 additions & 3 deletions gulpfile.coffee
Expand Up @@ -68,9 +68,9 @@ testBrowsers = (callback) ->
return # promises workaround: https://github.com/gulpjs/gulp/issues/455

gulp.task 'test-node', ['minify'], testNode
gulp.task 'test-browsers', ['minify'], testBrowsers
gulp.task 'test-browsers', ['build'], testBrowsers
gulp.task 'test', ['minify'], (callback) ->
Async.series [testNode, testBrowsers], (err) -> process.exit(if err then 1 else 0)
Async.series [testNode, testBrowsers], (err) -> not err || console.log(err); process.exit(if err then 1 else 0)
return # promises workaround: https://github.com/gulpjs/gulp/issues/455

gulp.task 'publish', ['minify'], (callback) ->
Expand All @@ -87,5 +87,5 @@ gulp.task 'publish', ['minify'], (callback) ->
gulp.src('packages/nuget/*.nuspec')
.pipe(nugetGulp())
.on('end', callback)
queue.await (err) -> process.exit(if err then 1 else 0)
queue.await (err) -> not err || console.log(err); process.exit(if err then 1 else 0)
return # promises workaround: https://github.com/gulpjs/gulp/issues/455
2 changes: 1 addition & 1 deletion knockback-full-stack.js
Expand Up @@ -4624,7 +4624,7 @@ kb.inputValidator = function(view_model, el, validation_options) {
(!options.validation_options) || (_.defaults(options.validation_options, validation_options), validation_options = options.validation_options);
bindings = {};
(!validators[type = el.getAttribute('type')]) || (bindings[type] = validators[type]);
(!el.getAttribute('required')) || (bindings.required = validators.required);
_.isUndefined(el.getAttribute('required')) || (bindings.required = validators.required);

This comment has been minimized.

Copy link
@wolasss

wolasss Mar 8, 2017

This is causing a bug, it should not be an undefined check since getAttribute returns null if is not set. Or you should rather use hasAttribute. #160

if (options.validations) {
ref1 = options.validations;
for (identifier in ref1) {
Expand Down
2 changes: 1 addition & 1 deletion knockback.js
Expand Up @@ -3069,7 +3069,7 @@ kb.inputValidator = function(view_model, el, validation_options) {
(!options.validation_options) || (_.defaults(options.validation_options, validation_options), validation_options = options.validation_options);
bindings = {};
(!validators[type = el.getAttribute('type')]) || (bindings[type] = validators[type]);
(!el.getAttribute('required')) || (bindings.required = validators.required);
_.isUndefined(el.getAttribute('required')) || (bindings.required = validators.required);
if (options.validations) {
ref1 = options.validations;
for (identifier in ref1) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -56,6 +56,7 @@
"gulp-wrap-amd-infer": "*",
"gulp-zip": "*",
"imports-loader": "*",
"jsdom": "^9.9.1",
"karma": "*",
"karma-chai": "*",
"karma-chrome-launcher": "*",
Expand Down
2 changes: 1 addition & 1 deletion src/validation/validation.coffee
Expand Up @@ -175,7 +175,7 @@ kb.inputValidator = (view_model, el, validation_options={}) ->
# collect the types to identifier
bindings = {}
(not validators[type = el.getAttribute('type')]) or (bindings[type] = validators[type])
(not el.getAttribute('required')) or (bindings.required = validators.required)
_.isUndefined(el.getAttribute('required')) or (bindings.required = validators.required)
if options.validations
bindings[identifier] = validator for identifier, validator of options.validations
result = kb.valueValidator(options.value, bindings, validation_options)
Expand Down
5 changes: 3 additions & 2 deletions test/spec/core/core.tests.coffee
Expand Up @@ -2,7 +2,8 @@ assert = assert or require?('chai').assert

describe 'knockback_core utils @quick @core', ->
kb = window?.kb; try kb or= require?('knockback') catch; try kb or= require?('../../../knockback')
{_, ko, $} = kb
{_, ko} = kb
$ = window?.$

it 'TEST DEPENDENCY MISSING', (done) ->
assert.ok(!!ko, 'ko')
Expand All @@ -13,7 +14,7 @@ describe 'knockback_core utils @quick @core', ->
done()

it 'kb.renderTemplate', (done) ->
return done() unless $
return done() unless ($ and window?.document)

kb.statistics = new kb.Statistics() # turn on stats

Expand Down
5 changes: 3 additions & 2 deletions test/spec/core/memory-management.tests.coffee
Expand Up @@ -3,7 +3,8 @@ assert = assert or require?('chai').assert
describe 'knockback.js memory management @quick @memory', ->

kb = window?.kb; try kb or= require?('knockback') catch; try kb or= require?('../../../knockback')
{_, ko, $} = kb
{_, ko} = kb
$ = window?.$

it 'TEST DEPENDENCY MISSING', (done) ->
assert.ok(!!ko, 'ko')
Expand Down Expand Up @@ -80,7 +81,7 @@ describe 'knockback.js memory management @quick @memory', ->
done()

it 'Releasing with nodes', (done) ->
return done() unless $
return done() unless ($ and window?.document)

kb.statistics = new kb.Statistics() # turn on stats

Expand Down
9 changes: 5 additions & 4 deletions test/spec/core/view-model.tests.coffee
Expand Up @@ -3,7 +3,8 @@ assert = assert or require?('chai').assert
describe 'view-model @quick @view-model', ->

kb = window?.kb; try kb or= require?('knockback') catch; try kb or= require?('../../../knockback')
{_, ko, $} = kb
{_, ko} = kb
$ = window?.$

it 'TEST DEPENDENCY MISSING', (done) ->
assert.ok(!!ko, 'ko')
Expand Down Expand Up @@ -563,7 +564,7 @@ describe 'view-model @quick @view-model', ->
done()

it '14. model replacement with select', (done) ->
return done() unless $
return done() unless ($ and window?.document)

kb.statistics = new kb.Statistics()

Expand Down Expand Up @@ -611,7 +612,7 @@ describe 'view-model @quick @view-model', ->
done()

it '16. model replacement with input', (done) ->
return done() unless $
return done() unless ($ and window?.document)

kb.statistics = new kb.Statistics()

Expand Down Expand Up @@ -655,7 +656,7 @@ describe 'view-model @quick @view-model', ->
done()

it '17. model replacement with multiple selects and weird backbone bug', (done) ->
return done() unless $
return done() unless ($ and window?.document)

kb.statistics = new kb.Statistics()

Expand Down
34 changes: 34 additions & 0 deletions test/spec/issues/159.tests.coffee
@@ -0,0 +1,34 @@
assert = assert or require?('chai').assert

# https://github.com/kmalakoff/knockback/issues/159
describe 'issue 159 @issue159 @quick', ->
kb = window?.kb; try kb or= require?('knockback') catch; try kb or= require?('../../../knockback')
{_, ko} = kb
$ = window?.$

it 'TEST DEPENDENCY MISSING', (done) ->
assert.ok(!!ko, 'ko')
assert.ok(!!_, '_')
assert.ok(!!kb.Model, 'kb.Model')
assert.ok(!!kb.Collection, 'kb.Collection')
assert.ok(!!kb, 'kb')
done()

it 'has no issue', (done) ->
return done() unless ($ and window?.document)

kb.statistics = new kb.Statistics() # turn on stats

class ViewModel
afterRender: -> @was_called = true

# test without options override
view_model = new ViewModel()
assert.ok(!view_model.was_called, 'afterRender not called yet')
el = $('<script type="text/x-jquery-tmpl" id="the_template1"><div>...</div></script>')
$('body').append(el)
kb.renderTemplate('the_template1', view_model)
assert.ok(view_model.was_called, 'afterRender was called')

assert.equal(kb.statistics.registeredStatsString('all released'), 'all released', "Cleanup: stats"); kb.statistics = null
done()
15 changes: 8 additions & 7 deletions test/spec/plugins/validation.tests.coffee
Expand Up @@ -3,7 +3,8 @@ window = if window? then window else global

describe 'validation @quick @validation', ->
kb = window?.kb; try kb or= require?('knockback') catch; try kb or= require?('../../../knockback')
{_, ko, $} = kb
{_, ko} = kb
$ = window?.$

it 'TEST DEPENDENCY MISSING', (done) ->
assert.ok(!!ko, 'ko')
Expand Down Expand Up @@ -48,7 +49,7 @@ describe 'validation @quick @validation', ->
done()

it 'kb.inputValidator', (done) ->
return done() unless $
return done() unless ($ and window?.document)
window.kb = kb unless window.kb # make kb global for bindings
kb.statistics = new kb.Statistics() # turn on stats

Expand Down Expand Up @@ -90,7 +91,7 @@ describe 'validation @quick @validation', ->
done()

it 'kb.inputValidator with custom validators', (done) ->
return done() unless $
return done() unless ($ and window?.document)
window.kb = kb unless window.kb # make kb global for bindings
kb.statistics = new kb.Statistics() # turn on stats

Expand Down Expand Up @@ -144,7 +145,7 @@ describe 'validation @quick @validation', ->
done()

it 'kb.inputValidator with validation_options', (done) ->
return done() unless $
return done() unless ($ and window?.document)
window.kb = kb unless window.kb # make kb global for bindings
kb.statistics = new kb.Statistics() # turn on stats

Expand Down Expand Up @@ -213,7 +214,7 @@ describe 'validation @quick @validation', ->
done()

it 'kb.formValidator with name', (done) ->
return done() unless $
return done() unless ($ and window?.document)
window.kb = kb unless window.kb # make kb global for bindings
kb.statistics = new kb.Statistics() # turn on stats

Expand Down Expand Up @@ -285,7 +286,7 @@ describe 'validation @quick @validation', ->
done()

it 'kb.formValidator no name with validation_options', (done) ->
return done() unless $
return done() unless ($ and window?.document)
window.kb = kb unless window.kb # make kb global for bindings
kb.statistics = new kb.Statistics() # turn on stats

Expand Down Expand Up @@ -364,7 +365,7 @@ describe 'validation @quick @validation', ->
done()

it 'kb.formValidator with inject and disable', (done) ->
return done() unless $
return done() unless ($ and window?.document)
window.kb = kb unless window.kb # make kb global for bindings
kb.statistics = new kb.Statistics() # turn on stats

Expand Down

0 comments on commit b7db9d2

Please sign in to comment.