Merge pull request #1114 from isiahmeadows/editorconfig
Add an editorconfig to the rewrite
This commit is contained in:
commit
8d4db4bfa9
90 changed files with 1707 additions and 1701 deletions
10
.editorconfig
Normal file
10
.editorconfig
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
|
||||||
|
[*.js]
|
||||||
|
indent_style = tab
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
|
end_of_line = lf
|
||||||
510
.eslintrc.js
510
.eslintrc.js
|
|
@ -1,257 +1,257 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
"env": {
|
"env": {
|
||||||
"browser": true,
|
"browser": true,
|
||||||
"commonjs": true,
|
"commonjs": true,
|
||||||
"node": true
|
"node": true
|
||||||
},
|
},
|
||||||
"globals": {
|
"globals": {
|
||||||
"Promise": true
|
"Promise": true
|
||||||
},
|
},
|
||||||
"extends": "eslint:recommended",
|
"extends": "eslint:recommended",
|
||||||
"rules": {
|
"rules": {
|
||||||
"accessor-pairs": "error",
|
"accessor-pairs": "error",
|
||||||
"array-bracket-spacing": [
|
"array-bracket-spacing": [
|
||||||
"error",
|
"error",
|
||||||
"never"
|
"never"
|
||||||
],
|
],
|
||||||
"array-callback-return": "error",
|
"array-callback-return": "error",
|
||||||
"arrow-body-style": "error",
|
"arrow-body-style": "error",
|
||||||
"arrow-parens": "error",
|
"arrow-parens": "error",
|
||||||
"arrow-spacing": "error",
|
"arrow-spacing": "error",
|
||||||
"block-scoped-var": "off",
|
"block-scoped-var": "off",
|
||||||
"block-spacing": [
|
"block-spacing": [
|
||||||
"error",
|
"error",
|
||||||
"never"
|
"never"
|
||||||
],
|
],
|
||||||
"brace-style": "off",
|
"brace-style": "off",
|
||||||
"callback-return": "off",
|
"callback-return": "off",
|
||||||
"camelcase": "error",
|
"camelcase": "error",
|
||||||
"comma-dangle": "off",
|
"comma-dangle": "off",
|
||||||
"comma-spacing": [
|
"comma-spacing": [
|
||||||
"error",
|
"error",
|
||||||
{
|
{
|
||||||
"after": true,
|
"after": true,
|
||||||
"before": false
|
"before": false
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"comma-style": [
|
"comma-style": [
|
||||||
"error",
|
"error",
|
||||||
"last"
|
"last"
|
||||||
],
|
],
|
||||||
"complexity": "off",
|
"complexity": "off",
|
||||||
"computed-property-spacing": [
|
"computed-property-spacing": [
|
||||||
"error",
|
"error",
|
||||||
"never"
|
"never"
|
||||||
],
|
],
|
||||||
"consistent-return": "off",
|
"consistent-return": "off",
|
||||||
"consistent-this": "off",
|
"consistent-this": "off",
|
||||||
"curly": "off",
|
"curly": "off",
|
||||||
"default-case": "off",
|
"default-case": "off",
|
||||||
"dot-location": [
|
"dot-location": [
|
||||||
"error",
|
"error",
|
||||||
"property"
|
"property"
|
||||||
],
|
],
|
||||||
"dot-notation": "off",
|
"dot-notation": "off",
|
||||||
"eol-last": "off",
|
"eol-last": "off",
|
||||||
"eqeqeq": "off",
|
"eqeqeq": "off",
|
||||||
"func-names": "off",
|
"func-names": "off",
|
||||||
"func-style": "off",
|
"func-style": "off",
|
||||||
"generator-star-spacing": "error",
|
"generator-star-spacing": "error",
|
||||||
"global-require": "error",
|
"global-require": "error",
|
||||||
"guard-for-in": "off",
|
"guard-for-in": "off",
|
||||||
"handle-callback-err": "error",
|
"handle-callback-err": "error",
|
||||||
"id-blacklist": "error",
|
"id-blacklist": "error",
|
||||||
"id-length": "off",
|
"id-length": "off",
|
||||||
"id-match": "error",
|
"id-match": "error",
|
||||||
"indent": "off",
|
"indent": "off",
|
||||||
"init-declarations": "off",
|
"init-declarations": "off",
|
||||||
"jsx-quotes": "error",
|
"jsx-quotes": "error",
|
||||||
"key-spacing": "error",
|
"key-spacing": "error",
|
||||||
"keyword-spacing": [
|
"keyword-spacing": [
|
||||||
"error",
|
"error",
|
||||||
{
|
{
|
||||||
"before": true,
|
"before": true,
|
||||||
"after": true
|
"after": true
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"lines-around-comment": "error",
|
"lines-around-comment": "error",
|
||||||
"max-depth": "off",
|
"max-depth": "off",
|
||||||
"max-len": "off",
|
"max-len": "off",
|
||||||
"max-nested-callbacks": "error",
|
"max-nested-callbacks": "error",
|
||||||
"max-params": "off",
|
"max-params": "off",
|
||||||
"max-statements": "off",
|
"max-statements": "off",
|
||||||
"max-statements-per-line": "off",
|
"max-statements-per-line": "off",
|
||||||
"new-parens": "off",
|
"new-parens": "off",
|
||||||
"newline-after-var": "off",
|
"newline-after-var": "off",
|
||||||
"newline-before-return": "off",
|
"newline-before-return": "off",
|
||||||
"newline-per-chained-call": "off",
|
"newline-per-chained-call": "off",
|
||||||
"no-alert": "error",
|
"no-alert": "error",
|
||||||
"no-array-constructor": "error",
|
"no-array-constructor": "error",
|
||||||
"no-bitwise": "off",
|
"no-bitwise": "off",
|
||||||
"no-caller": "error",
|
"no-caller": "error",
|
||||||
"no-catch-shadow": "error",
|
"no-catch-shadow": "error",
|
||||||
"no-cond-assign": "off",
|
"no-cond-assign": "off",
|
||||||
"no-confusing-arrow": "error",
|
"no-confusing-arrow": "error",
|
||||||
"no-continue": "error",
|
"no-continue": "error",
|
||||||
"no-div-regex": "error",
|
"no-div-regex": "error",
|
||||||
"no-duplicate-imports": "error",
|
"no-duplicate-imports": "error",
|
||||||
"no-else-return": "off",
|
"no-else-return": "off",
|
||||||
"no-empty-function": "off",
|
"no-empty-function": "off",
|
||||||
"no-eq-null": "off",
|
"no-eq-null": "off",
|
||||||
"no-eval": "error",
|
"no-eval": "error",
|
||||||
"no-extend-native": "error",
|
"no-extend-native": "error",
|
||||||
"no-extra-bind": "error",
|
"no-extra-bind": "error",
|
||||||
"no-extra-label": "error",
|
"no-extra-label": "error",
|
||||||
"no-extra-parens": "off",
|
"no-extra-parens": "off",
|
||||||
"no-floating-decimal": "error",
|
"no-floating-decimal": "error",
|
||||||
"no-implicit-coercion": "error",
|
"no-implicit-coercion": "error",
|
||||||
"no-implicit-globals": "error",
|
"no-implicit-globals": "error",
|
||||||
"no-implied-eval": "error",
|
"no-implied-eval": "error",
|
||||||
"no-inline-comments": "off",
|
"no-inline-comments": "off",
|
||||||
"no-inner-declarations": [
|
"no-inner-declarations": [
|
||||||
"error",
|
"error",
|
||||||
"functions"
|
"functions"
|
||||||
],
|
],
|
||||||
"no-invalid-this": "off",
|
"no-invalid-this": "off",
|
||||||
"no-iterator": "error",
|
"no-iterator": "error",
|
||||||
"no-label-var": "error",
|
"no-label-var": "error",
|
||||||
"no-labels": "error",
|
"no-labels": "error",
|
||||||
"no-lone-blocks": "error",
|
"no-lone-blocks": "error",
|
||||||
"no-lonely-if": "off",
|
"no-lonely-if": "off",
|
||||||
"no-loop-func": "off",
|
"no-loop-func": "off",
|
||||||
"no-magic-numbers": "off",
|
"no-magic-numbers": "off",
|
||||||
"no-mixed-requires": "error",
|
"no-mixed-requires": "error",
|
||||||
"no-multi-spaces": "error",
|
"no-multi-spaces": "error",
|
||||||
"no-multi-str": "error",
|
"no-multi-str": "error",
|
||||||
"no-multiple-empty-lines": "error",
|
"no-multiple-empty-lines": "error",
|
||||||
"no-native-reassign": "error",
|
"no-native-reassign": "error",
|
||||||
"no-negated-condition": "off",
|
"no-negated-condition": "off",
|
||||||
"no-nested-ternary": "off",
|
"no-nested-ternary": "off",
|
||||||
"no-new": "off",
|
"no-new": "off",
|
||||||
"no-new-func": "off",
|
"no-new-func": "off",
|
||||||
"no-new-object": "error",
|
"no-new-object": "error",
|
||||||
"no-new-require": "error",
|
"no-new-require": "error",
|
||||||
"no-new-wrappers": "error",
|
"no-new-wrappers": "error",
|
||||||
"no-octal-escape": "error",
|
"no-octal-escape": "error",
|
||||||
"no-param-reassign": "off",
|
"no-param-reassign": "off",
|
||||||
"no-path-concat": "error",
|
"no-path-concat": "error",
|
||||||
"no-plusplus": "off",
|
"no-plusplus": "off",
|
||||||
"no-process-env": "error",
|
"no-process-env": "error",
|
||||||
"no-process-exit": "error",
|
"no-process-exit": "error",
|
||||||
"no-proto": "error",
|
"no-proto": "error",
|
||||||
"no-redeclare": "off",
|
"no-redeclare": "off",
|
||||||
"no-restricted-globals": "error",
|
"no-restricted-globals": "error",
|
||||||
"no-restricted-imports": "error",
|
"no-restricted-imports": "error",
|
||||||
"no-restricted-modules": "error",
|
"no-restricted-modules": "error",
|
||||||
"no-restricted-syntax": "error",
|
"no-restricted-syntax": "error",
|
||||||
"no-return-assign": "off",
|
"no-return-assign": "off",
|
||||||
"no-script-url": "error",
|
"no-script-url": "error",
|
||||||
"no-self-compare": "error",
|
"no-self-compare": "error",
|
||||||
"no-sequences": "off",
|
"no-sequences": "off",
|
||||||
"no-shadow": "off",
|
"no-shadow": "off",
|
||||||
"no-shadow-restricted-names": "error",
|
"no-shadow-restricted-names": "error",
|
||||||
"no-spaced-func": "error",
|
"no-spaced-func": "error",
|
||||||
"no-sync": "off",
|
"no-sync": "off",
|
||||||
"no-ternary": "off",
|
"no-ternary": "off",
|
||||||
"no-throw-literal": "error",
|
"no-throw-literal": "error",
|
||||||
"no-trailing-spaces": [
|
"no-trailing-spaces": [
|
||||||
"error",
|
"error",
|
||||||
{
|
{
|
||||||
"skipBlankLines": true
|
"skipBlankLines": true
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"no-undef-init": "error",
|
"no-undef-init": "error",
|
||||||
"no-undefined": "off",
|
"no-undefined": "off",
|
||||||
"no-underscore-dangle": "error",
|
"no-underscore-dangle": "error",
|
||||||
"no-unmodified-loop-condition": "error",
|
"no-unmodified-loop-condition": "error",
|
||||||
"no-unneeded-ternary": "error",
|
"no-unneeded-ternary": "error",
|
||||||
"no-unsafe-finally": "error",
|
"no-unsafe-finally": "error",
|
||||||
"no-unused-expressions": "off",
|
"no-unused-expressions": "off",
|
||||||
"no-unused-vars": [
|
"no-unused-vars": [
|
||||||
"error",
|
"error",
|
||||||
{
|
{
|
||||||
"varsIgnorePattern": "module"
|
"varsIgnorePattern": "module"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"no-use-before-define": "off",
|
"no-use-before-define": "off",
|
||||||
"no-useless-call": "error",
|
"no-useless-call": "error",
|
||||||
"no-useless-computed-key": "error",
|
"no-useless-computed-key": "error",
|
||||||
"no-useless-concat": "error",
|
"no-useless-concat": "error",
|
||||||
"no-useless-constructor": "error",
|
"no-useless-constructor": "error",
|
||||||
"no-useless-escape": "off",
|
"no-useless-escape": "off",
|
||||||
"no-var": "off",
|
"no-var": "off",
|
||||||
"no-void": "error",
|
"no-void": "error",
|
||||||
"no-warning-comments": "off",
|
"no-warning-comments": "off",
|
||||||
"no-whitespace-before-property": "error",
|
"no-whitespace-before-property": "error",
|
||||||
"no-with": "error",
|
"no-with": "error",
|
||||||
"object-curly-spacing": [
|
"object-curly-spacing": [
|
||||||
"error",
|
"error",
|
||||||
"never"
|
"never"
|
||||||
],
|
],
|
||||||
"object-property-newline": [
|
"object-property-newline": [
|
||||||
"error",
|
"error",
|
||||||
{
|
{
|
||||||
"allowMultiplePropertiesPerLine": true
|
"allowMultiplePropertiesPerLine": true
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"object-shorthand": "off",
|
"object-shorthand": "off",
|
||||||
"one-var": "off",
|
"one-var": "off",
|
||||||
"one-var-declaration-per-line": "off",
|
"one-var-declaration-per-line": "off",
|
||||||
"operator-assignment": [
|
"operator-assignment": [
|
||||||
"error",
|
"error",
|
||||||
"always"
|
"always"
|
||||||
],
|
],
|
||||||
"operator-linebreak": [
|
"operator-linebreak": [
|
||||||
"error",
|
"error",
|
||||||
"after"
|
"after"
|
||||||
],
|
],
|
||||||
"padded-blocks": "off",
|
"padded-blocks": "off",
|
||||||
"prefer-arrow-callback": "off",
|
"prefer-arrow-callback": "off",
|
||||||
"prefer-const": "error",
|
"prefer-const": "error",
|
||||||
"prefer-reflect": "off",
|
"prefer-reflect": "off",
|
||||||
"prefer-rest-params": "off",
|
"prefer-rest-params": "off",
|
||||||
"prefer-spread": "off",
|
"prefer-spread": "off",
|
||||||
"prefer-template": "off",
|
"prefer-template": "off",
|
||||||
"quote-props": "off",
|
"quote-props": "off",
|
||||||
"quotes": [
|
"quotes": [
|
||||||
"error",
|
"error",
|
||||||
"double"
|
"double"
|
||||||
],
|
],
|
||||||
"radix": [
|
"radix": [
|
||||||
"error",
|
"error",
|
||||||
"as-needed"
|
"as-needed"
|
||||||
],
|
],
|
||||||
"require-jsdoc": "off",
|
"require-jsdoc": "off",
|
||||||
"require-yield": "error",
|
"require-yield": "error",
|
||||||
"semi": "off",
|
"semi": "off",
|
||||||
"semi-spacing": [
|
"semi-spacing": [
|
||||||
"error",
|
"error",
|
||||||
{
|
{
|
||||||
"after": true,
|
"after": true,
|
||||||
"before": false
|
"before": false
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"sort-imports": "error",
|
"sort-imports": "error",
|
||||||
"sort-vars": "off",
|
"sort-vars": "off",
|
||||||
"space-before-blocks": "error",
|
"space-before-blocks": "error",
|
||||||
"space-before-function-paren": "off",
|
"space-before-function-paren": "off",
|
||||||
"space-in-parens": [
|
"space-in-parens": [
|
||||||
"error",
|
"error",
|
||||||
"never"
|
"never"
|
||||||
],
|
],
|
||||||
"space-infix-ops": "error",
|
"space-infix-ops": "error",
|
||||||
"space-unary-ops": "off",
|
"space-unary-ops": "off",
|
||||||
"spaced-comment": "off",
|
"spaced-comment": "off",
|
||||||
"strict": "off",
|
"strict": "off",
|
||||||
"template-curly-spacing": "error",
|
"template-curly-spacing": "error",
|
||||||
"valid-jsdoc": "error",
|
"valid-jsdoc": "error",
|
||||||
"vars-on-top": "off",
|
"vars-on-top": "off",
|
||||||
"wrap-iife": "error",
|
"wrap-iife": "error",
|
||||||
"wrap-regex": "error",
|
"wrap-regex": "error",
|
||||||
"yield-star-spacing": "error",
|
"yield-star-spacing": "error",
|
||||||
"yoda": [
|
"yoda": [
|
||||||
"error",
|
"error",
|
||||||
"never"
|
"never"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -2,4 +2,4 @@ language: node_js
|
||||||
node_js:
|
node_js:
|
||||||
- stable
|
- stable
|
||||||
|
|
||||||
sudo: false
|
sudo: false
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,3 @@ Type checks are generally already irreducible expressions and having micro-modul
|
||||||
You should be trying to reduce the number of DOM operations or reduce algorithmic complexity in a hot spot. Anything else is likely a waste of time. Specifically, micro-optimizations like caching array lengths, caching object property values and inlining functions won't have any positive impact in modern javascript engines.
|
You should be trying to reduce the number of DOM operations or reduce algorithmic complexity in a hot spot. Anything else is likely a waste of time. Specifically, micro-optimizations like caching array lengths, caching object property values and inlining functions won't have any positive impact in modern javascript engines.
|
||||||
|
|
||||||
Keep object properties consistent (i.e. ensure the data objects always have the same properties and that properties are always in the same order) to allow the engine to keep using JIT'ed structs instead of hashmaps. Always place null checks first in compound type checking expressions to allow the Javascript engine to optimize to type-specific code paths. Prefer for loops over Array methods and try to pull conditionals out of loops if possible.
|
Keep object properties consistent (i.e. ensure the data objects always have the same properties and that properties are always in the same order) to allow the engine to keep using JIT'ed structs instead of hashmaps. Always place null checks first in compound type checking expressions to allow the Javascript engine to optimize to type-specific code paths. Prefer for loops over Array methods and try to pull conditionals out of loops if possible.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,11 @@ module.exports = function(root, renderer, pubsub, callback) {
|
||||||
if (e.redraw !== false) run()
|
if (e.redraw !== false) run()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pubsub != null) {
|
if (pubsub != null) {
|
||||||
if (root.redraw) pubsub.unsubscribe(root.redraw)
|
if (root.redraw) pubsub.unsubscribe(root.redraw)
|
||||||
pubsub.subscribe(run)
|
pubsub.subscribe(run)
|
||||||
}
|
}
|
||||||
|
|
||||||
return root.redraw = run
|
return root.redraw = run
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ module.exports = function(renderer, pubsub) {
|
||||||
var run = autoredraw(root, renderer, pubsub, function() {
|
var run = autoredraw(root, renderer, pubsub, function() {
|
||||||
renderer.render(root, {tag: component})
|
renderer.render(root, {tag: component})
|
||||||
})
|
})
|
||||||
|
|
||||||
run()
|
run()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,6 @@ module.exports = function($window, renderer, pubsub) {
|
||||||
route.prefix = router.setPrefix
|
route.prefix = router.setPrefix
|
||||||
route.setPath = router.setPath
|
route.setPath = router.setPath
|
||||||
route.getPath = router.getPath
|
route.getPath = router.getPath
|
||||||
|
|
||||||
return route
|
return route
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,13 +24,13 @@
|
||||||
<script src="../../api/autoredraw.js"></script>
|
<script src="../../api/autoredraw.js"></script>
|
||||||
<script src="../../api/mount.js"></script>
|
<script src="../../api/mount.js"></script>
|
||||||
<script src="../../api/router.js"></script>
|
<script src="../../api/router.js"></script>
|
||||||
|
|
||||||
<script src="./test-throttle.js"></script>
|
<script src="./test-throttle.js"></script>
|
||||||
<script src="./test-pubsub.js"></script>
|
<script src="./test-pubsub.js"></script>
|
||||||
<script src="./test-autoredraw.js"></script>
|
<script src="./test-autoredraw.js"></script>
|
||||||
<script src="./test-mount.js"></script>
|
<script src="./test-mount.js"></script>
|
||||||
<script src="./test-router.js"></script>
|
<script src="./test-router.js"></script>
|
||||||
|
|
||||||
<script>require("../../ospec/ospec").run()</script>
|
<script>require("../../ospec/ospec").run()</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
|
|
@ -17,79 +17,79 @@ o.spec("autoredraw", function() {
|
||||||
pubsub = apiPubSub()
|
pubsub = apiPubSub()
|
||||||
spy = o.spy()
|
spy = o.spy()
|
||||||
})
|
})
|
||||||
|
|
||||||
o("returns self-trigger", function() {
|
o("returns self-trigger", function() {
|
||||||
var run = autoredraw(root, renderer, pubsub, spy)
|
var run = autoredraw(root, renderer, pubsub, spy)
|
||||||
|
|
||||||
run()
|
run()
|
||||||
|
|
||||||
o(spy.callCount).equals(1)
|
o(spy.callCount).equals(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
o("null renderer doesn't throw", function(done) {
|
o("null renderer doesn't throw", function(done) {
|
||||||
autoredraw(root, null, pubsub, spy)
|
autoredraw(root, null, pubsub, spy)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
|
||||||
o("null pubsub doesn't throw", function(done) {
|
o("null pubsub doesn't throw", function(done) {
|
||||||
autoredraw(root, renderer, null, spy)
|
autoredraw(root, renderer, null, spy)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
|
||||||
o("registers onevent", function() {
|
o("registers onevent", function() {
|
||||||
autoredraw(root, renderer, pubsub, spy)
|
autoredraw(root, renderer, pubsub, spy)
|
||||||
|
|
||||||
renderer.render(root, {tag: "div", attrs: {onclick: function() {}}})
|
renderer.render(root, {tag: "div", attrs: {onclick: function() {}}})
|
||||||
|
|
||||||
var e = $window.document.createEvent("MouseEvents")
|
var e = $window.document.createEvent("MouseEvents")
|
||||||
e.initEvent("click", true, true)
|
e.initEvent("click", true, true)
|
||||||
root.firstChild.dispatchEvent(e)
|
root.firstChild.dispatchEvent(e)
|
||||||
|
|
||||||
o(spy.callCount).equals(1)
|
o(spy.callCount).equals(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
o("registers pubsub", function() {
|
o("registers pubsub", function() {
|
||||||
autoredraw(root, renderer, pubsub, spy)
|
autoredraw(root, renderer, pubsub, spy)
|
||||||
|
|
||||||
pubsub.publish()
|
pubsub.publish()
|
||||||
|
|
||||||
o(spy.callCount).equals(1)
|
o(spy.callCount).equals(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
o("re-registering pubsub works", function() {
|
o("re-registering pubsub works", function() {
|
||||||
autoredraw(root, renderer, pubsub, spy)
|
autoredraw(root, renderer, pubsub, spy)
|
||||||
autoredraw(root, renderer, pubsub, spy)
|
autoredraw(root, renderer, pubsub, spy)
|
||||||
|
|
||||||
pubsub.publish()
|
pubsub.publish()
|
||||||
|
|
||||||
o(spy.callCount).equals(1)
|
o(spy.callCount).equals(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
o("throttles", function(done) {
|
o("throttles", function(done) {
|
||||||
var run = autoredraw(root, renderer, pubsub, spy)
|
var run = autoredraw(root, renderer, pubsub, spy)
|
||||||
|
|
||||||
run()
|
run()
|
||||||
run()
|
run()
|
||||||
|
|
||||||
o(spy.callCount).equals(1)
|
o(spy.callCount).equals(1)
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
o(spy.callCount).equals(2)
|
o(spy.callCount).equals(2)
|
||||||
|
|
||||||
done()
|
done()
|
||||||
}, FRAME_BUDGET)
|
}, FRAME_BUDGET)
|
||||||
})
|
})
|
||||||
|
|
||||||
o("does not redraw if e.redraw is false", function() {
|
o("does not redraw if e.redraw is false", function() {
|
||||||
autoredraw(root, renderer, pubsub, spy)
|
autoredraw(root, renderer, pubsub, spy)
|
||||||
|
|
||||||
renderer.render(root, {tag: "div", attrs: {onclick: function(e) {e.redraw = false}}})
|
renderer.render(root, {tag: "div", attrs: {onclick: function(e) {e.redraw = false}}})
|
||||||
|
|
||||||
var e = $window.document.createEvent("MouseEvents")
|
var e = $window.document.createEvent("MouseEvents")
|
||||||
e.initEvent("click", true, true)
|
e.initEvent("click", true, true)
|
||||||
root.firstChild.dispatchEvent(e)
|
root.firstChild.dispatchEvent(e)
|
||||||
|
|
||||||
o(spy.callCount).equals(0)
|
o(spy.callCount).equals(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -11,34 +11,34 @@ var apiMounter = require("../../api/mount")
|
||||||
o.spec("mount", function() {
|
o.spec("mount", function() {
|
||||||
var FRAME_BUDGET = Math.floor(1000 / 60)
|
var FRAME_BUDGET = Math.floor(1000 / 60)
|
||||||
var $window, root, redraw, mount
|
var $window, root, redraw, mount
|
||||||
|
|
||||||
o.beforeEach(function() {
|
o.beforeEach(function() {
|
||||||
$window = domMock()
|
$window = domMock()
|
||||||
|
|
||||||
root = $window.document.body
|
root = $window.document.body
|
||||||
|
|
||||||
redraw = apiPubSub()
|
redraw = apiPubSub()
|
||||||
mount = apiMounter(coreRenderer($window), redraw)
|
mount = apiMounter(coreRenderer($window), redraw)
|
||||||
})
|
})
|
||||||
|
|
||||||
o("renders into `root`", function() {
|
o("renders into `root`", function() {
|
||||||
mount(root, {
|
mount(root, {
|
||||||
view : function() {
|
view : function() {
|
||||||
return m("div")
|
return m("div")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
o(root.firstChild.nodeName).equals("DIV")
|
o(root.firstChild.nodeName).equals("DIV")
|
||||||
})
|
})
|
||||||
|
|
||||||
o("redraws on events", function(done) {
|
o("redraws on events", function(done) {
|
||||||
var onupdate = o.spy()
|
var onupdate = o.spy()
|
||||||
var oninit = o.spy()
|
var oninit = o.spy()
|
||||||
var onclick = o.spy()
|
var onclick = o.spy()
|
||||||
var e = $window.document.createEvent("MouseEvents")
|
var e = $window.document.createEvent("MouseEvents")
|
||||||
|
|
||||||
e.initEvent("click", true, true)
|
e.initEvent("click", true, true)
|
||||||
|
|
||||||
mount(root, {
|
mount(root, {
|
||||||
view : function() {
|
view : function() {
|
||||||
return m("div", {
|
return m("div", {
|
||||||
|
|
@ -48,32 +48,32 @@ o.spec("mount", function() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
root.firstChild.dispatchEvent(e)
|
root.firstChild.dispatchEvent(e)
|
||||||
|
|
||||||
o(oninit.callCount).equals(1)
|
o(oninit.callCount).equals(1)
|
||||||
o(onupdate.callCount).equals(0)
|
o(onupdate.callCount).equals(0)
|
||||||
|
|
||||||
o(onclick.callCount).equals(1)
|
o(onclick.callCount).equals(1)
|
||||||
o(onclick.this).equals(root.firstChild)
|
o(onclick.this).equals(root.firstChild)
|
||||||
o(onclick.args[0].type).equals("click")
|
o(onclick.args[0].type).equals("click")
|
||||||
o(onclick.args[0].target).equals(root.firstChild)
|
o(onclick.args[0].target).equals(root.firstChild)
|
||||||
|
|
||||||
// Wrapped to give time for the rate-limited redraw to fire
|
// Wrapped to give time for the rate-limited redraw to fire
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
o(onupdate.callCount).equals(1)
|
o(onupdate.callCount).equals(1)
|
||||||
|
|
||||||
done()
|
done()
|
||||||
}, FRAME_BUDGET)
|
}, FRAME_BUDGET)
|
||||||
})
|
})
|
||||||
|
|
||||||
o("event handlers can skip redraw", function(done) {
|
o("event handlers can skip redraw", function(done) {
|
||||||
var onupdate = o.spy()
|
var onupdate = o.spy()
|
||||||
var oninit = o.spy()
|
var oninit = o.spy()
|
||||||
var e = $window.document.createEvent("MouseEvents")
|
var e = $window.document.createEvent("MouseEvents")
|
||||||
|
|
||||||
e.initEvent("click", true, true)
|
e.initEvent("click", true, true)
|
||||||
|
|
||||||
mount(root, {
|
mount(root, {
|
||||||
view: function() {
|
view: function() {
|
||||||
return m("div", {
|
return m("div", {
|
||||||
|
|
@ -85,23 +85,23 @@ o.spec("mount", function() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
root.firstChild.dispatchEvent(e)
|
root.firstChild.dispatchEvent(e)
|
||||||
|
|
||||||
o(oninit.callCount).equals(1)
|
o(oninit.callCount).equals(1)
|
||||||
|
|
||||||
// Wrapped to ensure no redraw fired
|
// Wrapped to ensure no redraw fired
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
o(onupdate.callCount).equals(0)
|
o(onupdate.callCount).equals(0)
|
||||||
|
|
||||||
done()
|
done()
|
||||||
}, FRAME_BUDGET)
|
}, FRAME_BUDGET)
|
||||||
})
|
})
|
||||||
|
|
||||||
o("redraws when the render function is run", function(done) {
|
o("redraws when the render function is run", function(done) {
|
||||||
var onupdate = o.spy()
|
var onupdate = o.spy()
|
||||||
var oninit = o.spy()
|
var oninit = o.spy()
|
||||||
|
|
||||||
mount(root, {
|
mount(root, {
|
||||||
view : function() {
|
view : function() {
|
||||||
return m("div", {
|
return m("div", {
|
||||||
|
|
@ -110,16 +110,16 @@ o.spec("mount", function() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
o(oninit.callCount).equals(1)
|
o(oninit.callCount).equals(1)
|
||||||
o(onupdate.callCount).equals(0)
|
o(onupdate.callCount).equals(0)
|
||||||
|
|
||||||
redraw.publish()
|
redraw.publish()
|
||||||
|
|
||||||
// Wrapped to give time for the rate-limited redraw to fire
|
// Wrapped to give time for the rate-limited redraw to fire
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
o(onupdate.callCount).equals(1)
|
o(onupdate.callCount).equals(1)
|
||||||
|
|
||||||
done()
|
done()
|
||||||
}, FRAME_BUDGET)
|
}, FRAME_BUDGET)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -8,68 +8,68 @@ o.spec("pubsub", function() {
|
||||||
o.beforeEach(function() {
|
o.beforeEach(function() {
|
||||||
pubsub = apiPubSub()
|
pubsub = apiPubSub()
|
||||||
})
|
})
|
||||||
|
|
||||||
o("shouldn't error if there are no renderers", function() {
|
o("shouldn't error if there are no renderers", function() {
|
||||||
pubsub.publish()
|
pubsub.publish()
|
||||||
})
|
})
|
||||||
|
|
||||||
o("should run a single renderer entry", function() {
|
o("should run a single renderer entry", function() {
|
||||||
var spy = o.spy()
|
var spy = o.spy()
|
||||||
|
|
||||||
pubsub.subscribe(spy)
|
pubsub.subscribe(spy)
|
||||||
|
|
||||||
pubsub.publish()
|
pubsub.publish()
|
||||||
|
|
||||||
o(spy.callCount).equals(1)
|
o(spy.callCount).equals(1)
|
||||||
|
|
||||||
pubsub.publish()
|
pubsub.publish()
|
||||||
pubsub.publish()
|
pubsub.publish()
|
||||||
pubsub.publish()
|
pubsub.publish()
|
||||||
|
|
||||||
o(spy.callCount).equals(4)
|
o(spy.callCount).equals(4)
|
||||||
})
|
})
|
||||||
|
|
||||||
o("should run all renderer entries", function() {
|
o("should run all renderer entries", function() {
|
||||||
var spy1 = o.spy()
|
var spy1 = o.spy()
|
||||||
var spy2 = o.spy()
|
var spy2 = o.spy()
|
||||||
var spy3 = o.spy()
|
var spy3 = o.spy()
|
||||||
|
|
||||||
pubsub.subscribe(spy1)
|
pubsub.subscribe(spy1)
|
||||||
pubsub.subscribe(spy2)
|
pubsub.subscribe(spy2)
|
||||||
pubsub.subscribe(spy3)
|
pubsub.subscribe(spy3)
|
||||||
|
|
||||||
pubsub.publish()
|
pubsub.publish()
|
||||||
|
|
||||||
o(spy1.callCount).equals(1)
|
o(spy1.callCount).equals(1)
|
||||||
o(spy2.callCount).equals(1)
|
o(spy2.callCount).equals(1)
|
||||||
o(spy3.callCount).equals(1)
|
o(spy3.callCount).equals(1)
|
||||||
|
|
||||||
pubsub.publish()
|
pubsub.publish()
|
||||||
|
|
||||||
o(spy1.callCount).equals(2)
|
o(spy1.callCount).equals(2)
|
||||||
o(spy2.callCount).equals(2)
|
o(spy2.callCount).equals(2)
|
||||||
o(spy3.callCount).equals(2)
|
o(spy3.callCount).equals(2)
|
||||||
})
|
})
|
||||||
|
|
||||||
o("should stop running after unsubscribe", function() {
|
o("should stop running after unsubscribe", function() {
|
||||||
var spy = o.spy()
|
var spy = o.spy()
|
||||||
|
|
||||||
pubsub.subscribe(spy)
|
pubsub.subscribe(spy)
|
||||||
pubsub.unsubscribe(spy)
|
pubsub.unsubscribe(spy)
|
||||||
|
|
||||||
pubsub.publish()
|
pubsub.publish()
|
||||||
|
|
||||||
o(spy.callCount).equals(0)
|
o(spy.callCount).equals(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
o("does nothing on invalid unsubscribe", function() {
|
o("does nothing on invalid unsubscribe", function() {
|
||||||
var spy = o.spy()
|
var spy = o.spy()
|
||||||
|
|
||||||
pubsub.subscribe(spy)
|
pubsub.subscribe(spy)
|
||||||
pubsub.unsubscribe(null)
|
pubsub.unsubscribe(null)
|
||||||
|
|
||||||
pubsub.publish()
|
pubsub.publish()
|
||||||
|
|
||||||
o(spy.callCount).equals(1)
|
o(spy.callCount).equals(1)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -1,170 +1,170 @@
|
||||||
"use strict"
|
"use strict"
|
||||||
|
|
||||||
var o = require("../../ospec/ospec")
|
var o = require("../../ospec/ospec")
|
||||||
var pushStateMock = require("../../test-utils/pushStateMock")
|
var pushStateMock = require("../../test-utils/pushStateMock")
|
||||||
var domMock = require("../../test-utils/domMock")
|
var domMock = require("../../test-utils/domMock")
|
||||||
|
|
||||||
var m = require("../../render/hyperscript")
|
var m = require("../../render/hyperscript")
|
||||||
var coreRenderer = require("../../render/render")
|
var coreRenderer = require("../../render/render")
|
||||||
var apiPubSub = require("../../api/pubsub")
|
var apiPubSub = require("../../api/pubsub")
|
||||||
var apiRouter = require("../../api/router")
|
var apiRouter = require("../../api/router")
|
||||||
|
|
||||||
o.spec("route", function() {
|
o.spec("route", function() {
|
||||||
var FRAME_BUDGET = Math.floor(1000 / 60)
|
var FRAME_BUDGET = Math.floor(1000 / 60)
|
||||||
var $window, root, redraw, route
|
var $window, root, redraw, route
|
||||||
|
|
||||||
o.beforeEach(function() {
|
o.beforeEach(function() {
|
||||||
$window = {}
|
$window = {}
|
||||||
|
|
||||||
var dom = domMock()
|
var dom = domMock()
|
||||||
for (var key in dom) $window[key] = dom[key]
|
for (var key in dom) $window[key] = dom[key]
|
||||||
|
|
||||||
var loc = pushStateMock()
|
var loc = pushStateMock()
|
||||||
for (var key in loc) $window[key] = loc[key]
|
for (var key in loc) $window[key] = loc[key]
|
||||||
|
|
||||||
root = $window.document.body
|
root = $window.document.body
|
||||||
|
|
||||||
redraw = apiPubSub()
|
redraw = apiPubSub()
|
||||||
route = apiRouter($window, coreRenderer($window), redraw)
|
route = apiRouter($window, coreRenderer($window), redraw)
|
||||||
})
|
})
|
||||||
|
|
||||||
o("renders into `root`", function() {
|
o("renders into `root`", function() {
|
||||||
route(root, "/", {
|
route(root, "/", {
|
||||||
"/" : {
|
"/" : {
|
||||||
view: function() {
|
view: function() {
|
||||||
return m("div")
|
return m("div")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
o(root.firstChild.nodeName).equals("DIV")
|
o(root.firstChild.nodeName).equals("DIV")
|
||||||
})
|
})
|
||||||
|
|
||||||
o("redraws when render function is executed", function(done) {
|
o("redraws when render function is executed", function(done) {
|
||||||
var onupdate = o.spy()
|
var onupdate = o.spy()
|
||||||
var oninit = o.spy()
|
var oninit = o.spy()
|
||||||
|
|
||||||
route(root, "/", {
|
route(root, "/", {
|
||||||
"/" : {
|
"/" : {
|
||||||
view: function() {
|
view: function() {
|
||||||
return m("div", {
|
return m("div", {
|
||||||
oninit: oninit,
|
oninit: oninit,
|
||||||
onupdate: onupdate
|
onupdate: onupdate
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
o(oninit.callCount).equals(1)
|
o(oninit.callCount).equals(1)
|
||||||
|
|
||||||
redraw.publish()
|
redraw.publish()
|
||||||
|
|
||||||
// Wrapped to give time for the rate-limited redraw to fire
|
// Wrapped to give time for the rate-limited redraw to fire
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
o(onupdate.callCount).equals(1)
|
o(onupdate.callCount).equals(1)
|
||||||
|
|
||||||
done()
|
done()
|
||||||
}, FRAME_BUDGET)
|
}, FRAME_BUDGET)
|
||||||
})
|
})
|
||||||
|
|
||||||
o("redraws on events", function(done, timeout) {
|
o("redraws on events", function(done, timeout) {
|
||||||
var onupdate = o.spy()
|
var onupdate = o.spy()
|
||||||
var oninit = o.spy()
|
var oninit = o.spy()
|
||||||
var onclick = o.spy()
|
var onclick = o.spy()
|
||||||
var e = $window.document.createEvent("MouseEvents")
|
var e = $window.document.createEvent("MouseEvents")
|
||||||
|
|
||||||
e.initEvent("click", true, true)
|
e.initEvent("click", true, true)
|
||||||
|
|
||||||
route(root, "/", {
|
route(root, "/", {
|
||||||
"/" : {
|
"/" : {
|
||||||
view: function() {
|
view: function() {
|
||||||
return m("div", {
|
return m("div", {
|
||||||
oninit: oninit,
|
oninit: oninit,
|
||||||
onupdate: onupdate,
|
onupdate: onupdate,
|
||||||
onclick: onclick,
|
onclick: onclick,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
root.firstChild.dispatchEvent(e)
|
root.firstChild.dispatchEvent(e)
|
||||||
|
|
||||||
o(oninit.callCount).equals(1)
|
o(oninit.callCount).equals(1)
|
||||||
|
|
||||||
o(onclick.callCount).equals(1)
|
o(onclick.callCount).equals(1)
|
||||||
o(onclick.this).equals(root.firstChild)
|
o(onclick.this).equals(root.firstChild)
|
||||||
o(onclick.args[0].type).equals("click")
|
o(onclick.args[0].type).equals("click")
|
||||||
o(onclick.args[0].target).equals(root.firstChild)
|
o(onclick.args[0].target).equals(root.firstChild)
|
||||||
|
|
||||||
// Wrapped to give time for the rate-limited redraw to fire
|
// Wrapped to give time for the rate-limited redraw to fire
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
o(onupdate.callCount).equals(1)
|
o(onupdate.callCount).equals(1)
|
||||||
|
|
||||||
done()
|
done()
|
||||||
}, FRAME_BUDGET)
|
}, FRAME_BUDGET)
|
||||||
})
|
})
|
||||||
|
|
||||||
o("event handlers can skip redraw", function(done) {
|
o("event handlers can skip redraw", function(done) {
|
||||||
var onupdate = o.spy()
|
var onupdate = o.spy()
|
||||||
var oninit = o.spy()
|
var oninit = o.spy()
|
||||||
var onclick = o.spy()
|
var onclick = o.spy()
|
||||||
var e = $window.document.createEvent("MouseEvents")
|
var e = $window.document.createEvent("MouseEvents")
|
||||||
|
|
||||||
e.initEvent("click", true, true)
|
e.initEvent("click", true, true)
|
||||||
|
|
||||||
route(root, "/", {
|
route(root, "/", {
|
||||||
"/" : {
|
"/" : {
|
||||||
view: function() {
|
view: function() {
|
||||||
return m("div", {
|
return m("div", {
|
||||||
oninit: oninit,
|
oninit: oninit,
|
||||||
onupdate: onupdate,
|
onupdate: onupdate,
|
||||||
onclick: function(e) {
|
onclick: function(e) {
|
||||||
e.redraw = false
|
e.redraw = false
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
root.firstChild.dispatchEvent(e)
|
root.firstChild.dispatchEvent(e)
|
||||||
|
|
||||||
o(oninit.callCount).equals(1)
|
o(oninit.callCount).equals(1)
|
||||||
|
|
||||||
// Wrapped to ensure no redraw fired
|
// Wrapped to ensure no redraw fired
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
o(onupdate.callCount).equals(0)
|
o(onupdate.callCount).equals(0)
|
||||||
|
|
||||||
done()
|
done()
|
||||||
}, FRAME_BUDGET)
|
}, FRAME_BUDGET)
|
||||||
})
|
})
|
||||||
|
|
||||||
o("changes location on route.link", function() {
|
o("changes location on route.link", function() {
|
||||||
var e = $window.document.createEvent("MouseEvents")
|
var e = $window.document.createEvent("MouseEvents")
|
||||||
|
|
||||||
e.initEvent("click", true, true)
|
e.initEvent("click", true, true)
|
||||||
|
|
||||||
route.prefix("?")
|
route.prefix("?")
|
||||||
|
|
||||||
route(root, "/", {
|
route(root, "/", {
|
||||||
"/" : {
|
"/" : {
|
||||||
view: function() {
|
view: function() {
|
||||||
return m("a", {
|
return m("a", {
|
||||||
href: "/test",
|
href: "/test",
|
||||||
oncreate: route.link
|
oncreate: route.link
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/test" : {
|
"/test" : {
|
||||||
view : function() {
|
view : function() {
|
||||||
return m("div")
|
return m("div")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
o($window.location.href).equals("http://localhost/?/")
|
o($window.location.href).equals("http://localhost/?/")
|
||||||
|
|
||||||
root.firstChild.dispatchEvent(e)
|
root.firstChild.dispatchEvent(e)
|
||||||
|
|
||||||
o($window.location.href).equals("http://localhost/?/test")
|
o($window.location.href).equals("http://localhost/?/test")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -11,74 +11,74 @@ o.spec("throttle", function() {
|
||||||
spy = o.spy()
|
spy = o.spy()
|
||||||
throttled = throttle(spy)
|
throttled = throttle(spy)
|
||||||
})
|
})
|
||||||
|
|
||||||
o("runs first call synchronously", function() {
|
o("runs first call synchronously", function() {
|
||||||
throttled()
|
throttled()
|
||||||
|
|
||||||
o(spy.callCount).equals(1)
|
o(spy.callCount).equals(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
o("throttles subsequent synchronous calls", function(done) {
|
o("throttles subsequent synchronous calls", function(done) {
|
||||||
throttled()
|
throttled()
|
||||||
throttled()
|
throttled()
|
||||||
|
|
||||||
o(spy.callCount).equals(1)
|
o(spy.callCount).equals(1)
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
o(spy.callCount).equals(2)
|
o(spy.callCount).equals(2)
|
||||||
|
|
||||||
done()
|
done()
|
||||||
}, FRAME_BUDGET) //this delay is much higher than 16.6ms due to setTimeout clamp and other runtime costs
|
}, FRAME_BUDGET) //this delay is much higher than 16.6ms due to setTimeout clamp and other runtime costs
|
||||||
})
|
})
|
||||||
|
|
||||||
o("calls after threshold", function(done) {
|
o("calls after threshold", function(done) {
|
||||||
throttled()
|
throttled()
|
||||||
|
|
||||||
o(spy.callCount).equals(1)
|
o(spy.callCount).equals(1)
|
||||||
|
|
||||||
setTimeout(function(t) {
|
setTimeout(function(t) {
|
||||||
throttled()
|
throttled()
|
||||||
|
|
||||||
o(spy.callCount).equals(2)
|
o(spy.callCount).equals(2)
|
||||||
|
|
||||||
done()
|
done()
|
||||||
}, FRAME_BUDGET)
|
}, FRAME_BUDGET)
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
o("throttles before threshold", function(done) {
|
o("throttles before threshold", function(done) {
|
||||||
throttled()
|
throttled()
|
||||||
|
|
||||||
o(spy.callCount).equals(1)
|
o(spy.callCount).equals(1)
|
||||||
|
|
||||||
callAsync(function(t) {
|
callAsync(function(t) {
|
||||||
throttled()
|
throttled()
|
||||||
|
|
||||||
o(spy.callCount).equals(1)
|
o(spy.callCount).equals(1)
|
||||||
|
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
o("it only runs once per tick", function(done) {
|
o("it only runs once per tick", function(done) {
|
||||||
throttled()
|
throttled()
|
||||||
throttled()
|
throttled()
|
||||||
throttled()
|
throttled()
|
||||||
|
|
||||||
o(spy.callCount).equals(1)
|
o(spy.callCount).equals(1)
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
o(spy.callCount).equals(2)
|
o(spy.callCount).equals(2)
|
||||||
|
|
||||||
done()
|
done()
|
||||||
}, FRAME_BUDGET)
|
}, FRAME_BUDGET)
|
||||||
})
|
})
|
||||||
|
|
||||||
o("it supports forcing a synchronous redraw", function() {
|
o("it supports forcing a synchronous redraw", function() {
|
||||||
throttled()
|
throttled()
|
||||||
throttled()
|
throttled()
|
||||||
throttled(true)
|
throttled(true)
|
||||||
|
|
||||||
o(spy.callCount).equals(2)
|
o(spy.callCount).equals(2)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ function resolve(dir, data) {
|
||||||
var replacements = []
|
var replacements = []
|
||||||
data = data.replace(/((?:var|let|const|)[\t ]*)([\w_$\.]+)(\s*=\s*)require\(([^\)]+)\)/g, function(match, def, variable, eq, dep) {
|
data = data.replace(/((?:var|let|const|)[\t ]*)([\w_$\.]+)(\s*=\s*)require\(([^\)]+)\)/g, function(match, def, variable, eq, dep) {
|
||||||
usedVariables[variable] = usedVariables[variable] ? usedVariables[variable]++ : 1
|
usedVariables[variable] = usedVariables[variable] ? usedVariables[variable]++ : 1
|
||||||
|
|
||||||
var filename = new Function("return " + dep).call()
|
var filename = new Function("return " + dep).call()
|
||||||
var normalized = path.resolve(dir, filename)
|
var normalized = path.resolve(dir, filename)
|
||||||
var pathname = path.dirname(normalized)
|
var pathname = path.dirname(normalized)
|
||||||
|
|
|
||||||
|
|
@ -229,7 +229,7 @@ To learn more about components, [see the components page](components.md).
|
||||||
|
|
||||||
### Lifecycle methods
|
### Lifecycle methods
|
||||||
|
|
||||||
Vnodes and components can have lifecycle methods (also known as *hooks*), which are called at various points during the lifetime of a DOM element. The lifecycle methods supported by Mithril are: `oninit`, `oncreate`, `onupdate`, `onbeforeremove`, `onremove`, and `onbeforeupdate`.
|
Vnodes and components can have lifecycle methods (also known as *hooks*), which are called at various points during the lifetime of a DOM element. The lifecycle methods supported by Mithril are: `oninit`, `oncreate`, `onupdate`, `onbeforeremove`, `onremove`, and `onbeforeupdate`.
|
||||||
|
|
||||||
Lifecycle methods are defined in the same way as DOM event handlers, but receive the vnode as an argument, instead of an Event object:
|
Lifecycle methods are defined in the same way as DOM event handlers, but receive the vnode as an argument, instead of an Event object:
|
||||||
|
|
||||||
|
|
@ -309,7 +309,7 @@ m("ul", users.map(function(u) { // <ul>
|
||||||
})) // </ul>
|
})) // </ul>
|
||||||
|
|
||||||
// ES6:
|
// ES6:
|
||||||
// m("ul", users.map(u =>
|
// m("ul", users.map(u =>
|
||||||
// m("li", u.name)
|
// m("li", u.name)
|
||||||
// ))
|
// ))
|
||||||
```
|
```
|
||||||
|
|
@ -392,7 +392,7 @@ var BadListComponent = {
|
||||||
for (var i = 0; i < vnode.attrs.items.length; i++) {
|
for (var i = 0; i < vnode.attrs.items.length; i++) {
|
||||||
list.push(m("li", vnode.attrs.items[i]))
|
list.push(m("li", vnode.attrs.items[i]))
|
||||||
}
|
}
|
||||||
|
|
||||||
return m("ul", list)
|
return m("ul", list)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -409,4 +409,4 @@ var BetterListComponent = {
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -150,4 +150,3 @@ var things = [
|
||||||
{id: 1, name: "Cup"},
|
{id: 1, name: "Cup"},
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -204,4 +204,4 @@ If a design-based solution is not feasible, and you must optimize a UI with a la
|
||||||
|
|
||||||
Avoid applying the optimization to other areas of your application "just-in-case". Remember that, generally speaking, more code incurs a higher maintenance cost than less code, and `onbeforeupdate` related bugs can be especially difficult to troubleshoot if you rely on object identity for its conditional checks.
|
Avoid applying the optimization to other areas of your application "just-in-case". Remember that, generally speaking, more code incurs a higher maintenance cost than less code, and `onbeforeupdate` related bugs can be especially difficult to troubleshoot if you rely on object identity for its conditional checks.
|
||||||
|
|
||||||
Again, **the `onbeforeupdate` hook should only be used as a last resort.**
|
Again, **the `onbeforeupdate` hook should only be used as a last resort.**
|
||||||
|
|
|
||||||
|
|
@ -33,4 +33,3 @@ This method is internally called by [`m.mount()`](mount.md) and [`m.route()`](ro
|
||||||
The `m.render` module is similar in scope to view libraries like Knockout, React and Vue. It is less than 500 lines of code (3kb min+gzip) and implements a virtual DOM diffing engine with a modern search space reduction algorithm and DOM recycling, which translate to top-of-class performance, both in terms of initial page load and re-rendering. It has no dependencies on other parts of Mithril and can be used as a standalone library.
|
The `m.render` module is similar in scope to view libraries like Knockout, React and Vue. It is less than 500 lines of code (3kb min+gzip) and implements a virtual DOM diffing engine with a modern search space reduction algorithm and DOM recycling, which translate to top-of-class performance, both in terms of initial page load and re-rendering. It has no dependencies on other parts of Mithril and can be used as a standalone library.
|
||||||
|
|
||||||
Despite being incredibly small, the render module is fully functional and self-suficient. It supports everything you might expect: SVG, custom elements, and all valid attributes and events - without any weird case-sensitive edge cases or exceptions. Of course, it also fully supports [components](components.md) and [lifecycle methods](lifecycle-methods.md).
|
Despite being incredibly small, the render module is fully functional and self-suficient. It supports everything you might expect: SVG, custom elements, and all valid attributes and events - without any weird case-sensitive edge cases or exceptions. Of course, it also fully supports [components](components.md) and [lifecycle methods](lifecycle-methods.md).
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,4 +31,4 @@ A splat argument means that if the last argument is an array, you can omit the s
|
||||||
|
|
||||||
In the example at the top, this means that `m("div", {id: "foo"}, ["a", "b", "c"])` can also be written as `m("div", {id: "foo"}, "a", "b", "c")`.
|
In the example at the top, this means that `m("div", {id: "foo"}, ["a", "b", "c"])` can also be written as `m("div", {id: "foo"}, "a", "b", "c")`.
|
||||||
|
|
||||||
Splats are useful in some compile-to-js languages such as Coffeescript, and also allow helpful shorthands for some common use cases.
|
Splats are useful in some compile-to-js languages such as Coffeescript, and also allow helpful shorthands for some common use cases.
|
||||||
|
|
|
||||||
|
|
@ -101,10 +101,10 @@ Here's the example snippet for the [Facebook Like button](https://developers.fac
|
||||||
}(document, 'script', 'facebook-jssdk'));</script>
|
}(document, 'script', 'facebook-jssdk'));</script>
|
||||||
|
|
||||||
<!-- Your like button code -->
|
<!-- Your like button code -->
|
||||||
<div class="fb-like"
|
<div class="fb-like"
|
||||||
data-href="http://www.your-domain.com/your-page.html"
|
data-href="http://www.your-domain.com/your-page.html"
|
||||||
data-layout="standard"
|
data-layout="standard"
|
||||||
data-action="like"
|
data-action="like"
|
||||||
data-show-faces="true">
|
data-show-faces="true">
|
||||||
</div>
|
</div>
|
||||||
```
|
```
|
||||||
|
|
@ -149,4 +149,4 @@ Unicode characters for accented characters can be typed using a keyboard layout
|
||||||
|
|
||||||
All characters that are representable as HTML entities have unicode counterparts, including non-visible characters such as ` ` and `­`.
|
All characters that are representable as HTML entities have unicode counterparts, including non-visible characters such as ` ` and `­`.
|
||||||
|
|
||||||
To avoid encoding issues, you should set the file encoding to UTF-8 on the Javascript file, as well as add the `<meta charset="utf-8">` meta tag in the host HTML file.
|
To avoid encoding issues, you should set the file encoding to UTF-8 on the Javascript file, as well as add the `<meta charset="utf-8">` meta tag in the host HTML file.
|
||||||
|
|
|
||||||
|
|
@ -85,10 +85,10 @@ In `v1.x` there is no more `controller` property in components, use `oninit` ins
|
||||||
m.mount(document.body, {
|
m.mount(document.body, {
|
||||||
controller : function() {
|
controller : function() {
|
||||||
var ctrl = this;
|
var ctrl = this;
|
||||||
|
|
||||||
ctrl.fooga = 1;
|
ctrl.fooga = 1;
|
||||||
},
|
},
|
||||||
|
|
||||||
view : function(ctrl) {
|
view : function(ctrl) {
|
||||||
return m("p", ctrl.fooga);
|
return m("p", ctrl.fooga);
|
||||||
}
|
}
|
||||||
|
|
@ -102,7 +102,7 @@ m.mount(document.body, {
|
||||||
oninit : function(vnode) {
|
oninit : function(vnode) {
|
||||||
vnode.state.fooga = 1;
|
vnode.state.fooga = 1;
|
||||||
},
|
},
|
||||||
|
|
||||||
view : function(vnode) {
|
view : function(vnode) {
|
||||||
return m("p", vnode.state.fooga);
|
return m("p", vnode.state.fooga);
|
||||||
}
|
}
|
||||||
|
|
@ -113,13 +113,13 @@ m.mount(document.body, {
|
||||||
m.mount(document.body, {
|
m.mount(document.body, {
|
||||||
oninit : function(vnode) {
|
oninit : function(vnode) {
|
||||||
var ctrl = this; // this is bound to vnode.state by default
|
var ctrl = this; // this is bound to vnode.state by default
|
||||||
|
|
||||||
ctrl.fooga = 1;
|
ctrl.fooga = 1;
|
||||||
},
|
},
|
||||||
|
|
||||||
view : function(vnode) {
|
view : function(vnode) {
|
||||||
var ctrl = this; // this is bound to vnode.state by default
|
var ctrl = this; // this is bound to vnode.state by default
|
||||||
|
|
||||||
return m("p", ctrl.fooga);
|
return m("p", ctrl.fooga);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -136,7 +136,7 @@ var component = {
|
||||||
controller : function(options) {
|
controller : function(options) {
|
||||||
// options.fooga === 1
|
// options.fooga === 1
|
||||||
},
|
},
|
||||||
|
|
||||||
view : function(ctrl, options) {
|
view : function(ctrl, options) {
|
||||||
// options.fooga == 1
|
// options.fooga == 1
|
||||||
}
|
}
|
||||||
|
|
@ -152,7 +152,7 @@ var component = {
|
||||||
oninit : function(vnode) {
|
oninit : function(vnode) {
|
||||||
// vnode.attrs.fooga === 1
|
// vnode.attrs.fooga === 1
|
||||||
},
|
},
|
||||||
|
|
||||||
view : function(vnode) {
|
view : function(vnode) {
|
||||||
// vnode.attrs.fooga == 1
|
// vnode.attrs.fooga == 1
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -99,4 +99,4 @@ Only element tag names and components can be the first argument of the `m()` fun
|
||||||
|
|
||||||
The `mithril/render/node` module is used by Mithril to generate all vnodes. This ensures modern Javascript engines can optimize virtual dom diffing by always compiling vnodes to the same hidden class.
|
The `mithril/render/node` module is used by Mithril to generate all vnodes. This ensures modern Javascript engines can optimize virtual dom diffing by always compiling vnodes to the same hidden class.
|
||||||
|
|
||||||
When creating libraries that emit vnodes, you should use this module instead of writing naked Javascript objects in order to ensure a high level of rendering performance.
|
When creating libraries that emit vnodes, you should use this module instead of writing naked Javascript objects in order to ensure a high level of rendering performance.
|
||||||
|
|
|
||||||
5
index.js
5
index.js
|
|
@ -1,4 +1,7 @@
|
||||||
"use strict"
|
"use strict"
|
||||||
|
|
||||||
|
/* eslint-disable global-require */
|
||||||
|
|
||||||
;(function () {
|
;(function () {
|
||||||
var Promise = require("./promise/promise")
|
var Promise = require("./promise/promise")
|
||||||
var m = require("./render/hyperscript")
|
var m = require("./render/hyperscript")
|
||||||
|
|
@ -18,4 +21,4 @@
|
||||||
|
|
||||||
if (typeof module === "object") module.exports = m
|
if (typeof module === "object") module.exports = m
|
||||||
else window.m = m
|
else window.m = m
|
||||||
})()
|
}())
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ Assertions may have descriptions:
|
||||||
```javascript
|
```javascript
|
||||||
o("addition", function() {
|
o("addition", function() {
|
||||||
o(1 + 1).equals(2)("addition should work")
|
o(1 + 1).equals(2)("addition should work")
|
||||||
|
|
||||||
/* in ES6, the following syntax is also possible
|
/* in ES6, the following syntax is also possible
|
||||||
o(1 + 1).equals(2) `addition should work`
|
o(1 + 1).equals(2) `addition should work`
|
||||||
*/
|
*/
|
||||||
|
|
@ -110,7 +110,7 @@ o.spec("call()", function() {
|
||||||
o("works", function() {
|
o("works", function() {
|
||||||
var spy = o.spy()
|
var spy = o.spy()
|
||||||
call(spy, 1)
|
call(spy, 1)
|
||||||
|
|
||||||
o(spy.callCount).equals(1)
|
o(spy.callCount).equals(1)
|
||||||
o(spy.args[0]).equals(1)
|
o(spy.args[0]).equals(1)
|
||||||
})
|
})
|
||||||
|
|
@ -132,7 +132,7 @@ By default, asynchronous tests time out after 20ms. This can be changed on a per
|
||||||
```javascript
|
```javascript
|
||||||
o("setTimeout calls callback", function(done, timeout) {
|
o("setTimeout calls callback", function(done, timeout) {
|
||||||
timeout(50) //wait 50ms before bailing out of the test
|
timeout(50) //wait 50ms before bailing out of the test
|
||||||
|
|
||||||
setTimeout(done, 30)
|
setTimeout(done, 30)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
@ -151,15 +151,15 @@ o.spec("math", function() {
|
||||||
o.beforeEach(function() {
|
o.beforeEach(function() {
|
||||||
acc = 0
|
acc = 0
|
||||||
})
|
})
|
||||||
|
|
||||||
o("addition", function() {
|
o("addition", function() {
|
||||||
acc += 1
|
acc += 1
|
||||||
|
|
||||||
o(acc).equals(1)
|
o(acc).equals(1)
|
||||||
})
|
})
|
||||||
o("subtraction", function() {
|
o("subtraction", function() {
|
||||||
acc -= 1
|
acc -= 1
|
||||||
|
|
||||||
o(acc).equals(-1)
|
o(acc).equals(-1)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
@ -180,16 +180,16 @@ o.spec("math", function() {
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
//tests only run after async hooks complete
|
//tests only run after async hooks complete
|
||||||
o("addition", function() {
|
o("addition", function() {
|
||||||
acc += 1
|
acc += 1
|
||||||
|
|
||||||
o(acc).equals(1)
|
o(acc).equals(1)
|
||||||
})
|
})
|
||||||
o("subtraction", function() {
|
o("subtraction", function() {
|
||||||
acc -= 1
|
acc -= 1
|
||||||
|
|
||||||
o(acc).equals(-1)
|
o(acc).equals(-1)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
@ -204,7 +204,7 @@ o.spec("math", function() {
|
||||||
o("addition", function() {
|
o("addition", function() {
|
||||||
o(1 + 1).equals(2)
|
o(1 + 1).equals(2)
|
||||||
})
|
})
|
||||||
|
|
||||||
//only this test will be run, regardless of how many groups there are
|
//only this test will be run, regardless of how many groups there are
|
||||||
o.only("subtraction", function() {
|
o.only("subtraction", function() {
|
||||||
o(1 - 1).notEquals(2)
|
o(1 - 1).notEquals(2)
|
||||||
|
|
|
||||||
|
|
@ -43,4 +43,4 @@ traverseDirectory(".", function(pathname, stat, children) {
|
||||||
|
|
||||||
process.on("unhandledRejection", function(e) {
|
process.on("unhandledRejection", function(e) {
|
||||||
console.log("Uncaught (in promise) " + e.stack)
|
console.log("Uncaught (in promise) " + e.stack)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
node cli
|
node cli
|
||||||
|
|
|
||||||
|
|
@ -32,21 +32,21 @@ module.exports = new function init() {
|
||||||
o.run = function() {
|
o.run = function() {
|
||||||
start = new Date
|
start = new Date
|
||||||
test(spec, [], [], report)
|
test(spec, [], [], report)
|
||||||
|
|
||||||
function test(spec, pre, post, finalize) {
|
function test(spec, pre, post, finalize) {
|
||||||
pre = [].concat(pre, spec["__beforeEach"] || [])
|
pre = [].concat(pre, spec["__beforeEach"] || [])
|
||||||
post = [].concat(spec["__afterEach"] || [], post)
|
post = [].concat(spec["__afterEach"] || [], post)
|
||||||
series([].concat(spec["__before"] || [], Object.keys(spec).map(function(key) {
|
series([].concat(spec["__before"] || [], Object.keys(spec).map(function(key) {
|
||||||
return function(done, timeout) {
|
return function(done, timeout) {
|
||||||
timeout(Infinity)
|
timeout(Infinity)
|
||||||
|
|
||||||
if (key.slice(0, 2) === "__") return done()
|
if (key.slice(0, 2) === "__") return done()
|
||||||
if (only !== null && spec[key] !== only && typeof only === typeof spec[key]) return done()
|
if (only !== null && spec[key] !== only && typeof only === typeof spec[key]) return done()
|
||||||
subjects.push(key)
|
subjects.push(key)
|
||||||
var type = typeof spec[key]
|
var type = typeof spec[key]
|
||||||
if (type === "object") test(spec[key], pre, post, pop)
|
if (type === "object") test(spec[key], pre, post, pop)
|
||||||
if (type === "function") series([].concat(pre, spec[key], post, pop))
|
if (type === "function") series([].concat(pre, spec[key], post, pop))
|
||||||
|
|
||||||
function pop() {
|
function pop() {
|
||||||
subjects.pop()
|
subjects.pop()
|
||||||
done()
|
done()
|
||||||
|
|
@ -58,11 +58,11 @@ module.exports = new function init() {
|
||||||
function series(fns) {
|
function series(fns) {
|
||||||
var cursor = 0
|
var cursor = 0
|
||||||
next()
|
next()
|
||||||
|
|
||||||
function next() {
|
function next() {
|
||||||
stack++
|
stack++
|
||||||
if (cursor === fns.length) return
|
if (cursor === fns.length) return
|
||||||
|
|
||||||
var fn = fns[cursor++]
|
var fn = fns[cursor++]
|
||||||
if (fn.length > 0) {
|
if (fn.length > 0) {
|
||||||
var timeout = 0, delay = 40, s = new Date
|
var timeout = 0, delay = 40, s = new Date
|
||||||
|
|
@ -108,12 +108,12 @@ module.exports = new function init() {
|
||||||
ctx[name] = predicate
|
ctx[name] = predicate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
define("equals", "should equal", function(a, b) {return a === b})
|
define("equals", "should equal", function(a, b) {return a === b})
|
||||||
define("notEquals", "should not equal", function(a, b) {return a !== b})
|
define("notEquals", "should not equal", function(a, b) {return a !== b})
|
||||||
define("deepEquals", "should deep equal", deepEqual)
|
define("deepEquals", "should deep equal", deepEqual)
|
||||||
define("notDeepEquals", "should not deep equal", function(a, b) {return !deepEqual(a, b)})
|
define("notDeepEquals", "should not deep equal", function(a, b) {return !deepEqual(a, b)})
|
||||||
|
|
||||||
function isArguments(a) {
|
function isArguments(a) {
|
||||||
if ("callee" in a) {
|
if ("callee" in a) {
|
||||||
for (var i in a) if (i === "callee") return false
|
for (var i in a) if (i === "callee") return false
|
||||||
|
|
@ -184,7 +184,7 @@ module.exports = new function init() {
|
||||||
function highlight(message) {
|
function highlight(message) {
|
||||||
return hasProcess ? "\x1b[31m" + message + "\x1b[0m" : "%c" + message + "%c "
|
return hasProcess ? "\x1b[31m" + message + "\x1b[0m" : "%c" + message + "%c "
|
||||||
}
|
}
|
||||||
|
|
||||||
function report() {
|
function report() {
|
||||||
var status = 0
|
var status = 0
|
||||||
for (var i = 0, r; r = results[i]; i++) {
|
for (var i = 0, r; r = results[i]; i++) {
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,9 @@
|
||||||
<body>
|
<body>
|
||||||
<script src="../../module/module.js"></script>
|
<script src="../../module/module.js"></script>
|
||||||
<script src="../../test-utils/callAsync.js"></script>
|
<script src="../../test-utils/callAsync.js"></script>
|
||||||
|
|
||||||
<script src="../../ospec/ospec.js"></script>
|
<script src="../../ospec/ospec.js"></script>
|
||||||
<script src="test-ospec.js"></script>
|
<script src="test-ospec.js"></script>
|
||||||
<script>require("../../ospec/ospec").run()</script>
|
<script>require("../../ospec/ospec").run()</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
|
|
@ -21,22 +21,22 @@ new function(o) {
|
||||||
o.spec("ospec", function() {
|
o.spec("ospec", function() {
|
||||||
o.spec("sync", function() {
|
o.spec("sync", function() {
|
||||||
var a = 0, b = 0
|
var a = 0, b = 0
|
||||||
|
|
||||||
o.before(function test() {a = 1})
|
o.before(function test() {a = 1})
|
||||||
o.after(function test() {a = 0})
|
o.after(function test() {a = 0})
|
||||||
|
|
||||||
o.beforeEach(function test() {b = 1})
|
o.beforeEach(function test() {b = 1})
|
||||||
o.afterEach(function test() {b = 0})
|
o.afterEach(function test() {b = 0})
|
||||||
|
|
||||||
o("assertions", function test() {
|
o("assertions", function test() {
|
||||||
var spy = o.spy()
|
var spy = o.spy()
|
||||||
spy(a)
|
spy(a)
|
||||||
|
|
||||||
o(a).equals(b)
|
o(a).equals(b)
|
||||||
o(a).notEquals(2)
|
o(a).notEquals(2)
|
||||||
o({a: [1, 2], b: 3}).deepEquals({a: [1, 2], b: 3})
|
o({a: [1, 2], b: 3}).deepEquals({a: [1, 2], b: 3})
|
||||||
o([{a: 1, b: 2}, {c: 3}]).deepEquals([{a: 1, b: 2}, {c: 3}])
|
o([{a: 1, b: 2}, {c: 3}]).deepEquals([{a: 1, b: 2}, {c: 3}])
|
||||||
|
|
||||||
var values = ["a", "", 1, 0, true, false, null, undefined, Date(0), ["a"], [], function() {return arguments}.call(), new Uint8Array(), {a: 1}, {}]
|
var values = ["a", "", 1, 0, true, false, null, undefined, Date(0), ["a"], [], function() {return arguments}.call(), new Uint8Array(), {a: 1}, {}]
|
||||||
for (var i = 0; i < values.length; i++) {
|
for (var i = 0; i < values.length; i++) {
|
||||||
for (var j = 0; j < values.length; j++) {
|
for (var j = 0; j < values.length; j++) {
|
||||||
|
|
@ -44,7 +44,7 @@ o.spec("ospec", function() {
|
||||||
else o(values[i]).notDeepEquals(values[j])
|
else o(values[i]).notDeepEquals(values[j])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
o(spy.callCount).equals(1)
|
o(spy.callCount).equals(1)
|
||||||
o(spy.args.length).equals(1)
|
o(spy.args.length).equals(1)
|
||||||
o(spy.args[0]).equals(1)
|
o(spy.args[0]).equals(1)
|
||||||
|
|
@ -52,7 +52,7 @@ o.spec("ospec", function() {
|
||||||
})
|
})
|
||||||
o.spec("async", function() {
|
o.spec("async", function() {
|
||||||
var a = 0, b = 0
|
var a = 0, b = 0
|
||||||
|
|
||||||
o.before(function test(done) {
|
o.before(function test(done) {
|
||||||
callAsync(function() {
|
callAsync(function() {
|
||||||
a = 1
|
a = 1
|
||||||
|
|
@ -65,7 +65,7 @@ o.spec("ospec", function() {
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
o.beforeEach(function test(done) {
|
o.beforeEach(function test(done) {
|
||||||
callAsync(function() {
|
callAsync(function() {
|
||||||
b = 1
|
b = 1
|
||||||
|
|
@ -78,15 +78,15 @@ o.spec("ospec", function() {
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
o("async hooks", function test(done) {
|
o("async hooks", function test(done) {
|
||||||
callAsync(function() {
|
callAsync(function() {
|
||||||
var spy = o.spy()
|
var spy = o.spy()
|
||||||
spy(a)
|
spy(a)
|
||||||
|
|
||||||
o(a).equals(b)
|
o(a).equals(b)
|
||||||
o(a).equals(1)("a and b should be initialized")
|
o(a).equals(1)("a and b should be initialized")
|
||||||
|
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
var Promise = function(executor) {
|
var Promise = function(executor) {
|
||||||
if (!(this instanceof Promise)) throw new Error("Promise must be called with `new`")
|
if (!(this instanceof Promise)) throw new Error("Promise must be called with `new`")
|
||||||
if (typeof executor !== "function") throw new TypeError("executor must be a function")
|
if (typeof executor !== "function") throw new TypeError("executor must be a function")
|
||||||
|
|
||||||
var self = this, resolvers = [], rejectors = [], resolveCurrent = handler(resolvers, true), rejectCurrent = handler(rejectors, false)
|
var self = this, resolvers = [], rejectors = [], resolveCurrent = handler(resolvers, true), rejectCurrent = handler(rejectors, false)
|
||||||
var instance = self._instance = {resolvers: resolvers, rejectors: rejectors}
|
var instance = self._instance = {resolvers: resolvers, rejectors: rejectors}
|
||||||
var callAsync = typeof setImmediate === "function" ? setImmediate : setTimeout
|
var callAsync = typeof setImmediate === "function" ? setImmediate : setTimeout
|
||||||
|
|
@ -41,7 +41,7 @@ var Promise = function(executor) {
|
||||||
var onerror = run(rejectCurrent)
|
var onerror = run(rejectCurrent)
|
||||||
try {then(run(resolveCurrent), onerror)} catch (e) {onerror(e)}
|
try {then(run(resolveCurrent), onerror)} catch (e) {onerror(e)}
|
||||||
}
|
}
|
||||||
|
|
||||||
executeOnce(executor)
|
executeOnce(executor)
|
||||||
}
|
}
|
||||||
Promise.prototype.then = function(onFulfilled, onRejection) {
|
Promise.prototype.then = function(onFulfilled, onRejection) {
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
<script src="../../promise/promise.js"></script>
|
<script src="../../promise/promise.js"></script>
|
||||||
<script src="test-promise.js"></script>
|
<script src="test-promise.js"></script>
|
||||||
|
|
||||||
<script>require("../../ospec/ospec").run()</script>
|
<script>require("../../ospec/ospec").run()</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
|
|
@ -24,31 +24,31 @@ o.spec("promise", function() {
|
||||||
o.spec("return value", function() {
|
o.spec("return value", function() {
|
||||||
o("static resolve returns promise", function() {
|
o("static resolve returns promise", function() {
|
||||||
var promise = Promise.resolve()
|
var promise = Promise.resolve()
|
||||||
|
|
||||||
o(promise instanceof Promise).equals(true)
|
o(promise instanceof Promise).equals(true)
|
||||||
})
|
})
|
||||||
o("static resolve returns promise", function() {
|
o("static resolve returns promise", function() {
|
||||||
var promise = Promise.reject()
|
var promise = Promise.reject()
|
||||||
promise.catch(function() {})
|
promise.catch(function() {})
|
||||||
|
|
||||||
o(promise instanceof Promise).equals(true)
|
o(promise instanceof Promise).equals(true)
|
||||||
})
|
})
|
||||||
o("static resolve with promise input returns same promise", function() {
|
o("static resolve with promise input returns same promise", function() {
|
||||||
var resolved = Promise.resolve(1)
|
var resolved = Promise.resolve(1)
|
||||||
var promise = Promise.resolve(resolved)
|
var promise = Promise.resolve(resolved)
|
||||||
|
|
||||||
o(promise).equals(resolved)
|
o(promise).equals(resolved)
|
||||||
})
|
})
|
||||||
o("then returns promise", function(done) {
|
o("then returns promise", function(done) {
|
||||||
var promise = Promise.resolve(1)
|
var promise = Promise.resolve(1)
|
||||||
|
|
||||||
promise.then(function(value) {
|
promise.then(function(value) {
|
||||||
o(value).equals(1)
|
o(value).equals(1)
|
||||||
}).then(done)
|
}).then(done)
|
||||||
})
|
})
|
||||||
o("catch returns promise", function(done) {
|
o("catch returns promise", function(done) {
|
||||||
var promise = Promise.reject(1)
|
var promise = Promise.reject(1)
|
||||||
|
|
||||||
promise.catch(function(value) {
|
promise.catch(function(value) {
|
||||||
o(value).equals(1)
|
o(value).equals(1)
|
||||||
}).then(done)
|
}).then(done)
|
||||||
|
|
@ -62,10 +62,10 @@ o.spec("promise", function() {
|
||||||
resolve(2)
|
resolve(2)
|
||||||
callAsync(function() {resolve(3)})
|
callAsync(function() {resolve(3)})
|
||||||
})
|
})
|
||||||
|
|
||||||
promise.then(function(value) {
|
promise.then(function(value) {
|
||||||
callCount++
|
callCount++
|
||||||
|
|
||||||
o(value).equals(1)
|
o(value).equals(1)
|
||||||
o(callCount).equals(1)
|
o(callCount).equals(1)
|
||||||
done()
|
done()
|
||||||
|
|
@ -77,7 +77,7 @@ o.spec("promise", function() {
|
||||||
reject(2)
|
reject(2)
|
||||||
callAsync(function() {reject(3)})
|
callAsync(function() {reject(3)})
|
||||||
})
|
})
|
||||||
|
|
||||||
promise.then(function(value) {
|
promise.then(function(value) {
|
||||||
o(value).equals(1)
|
o(value).equals(1)
|
||||||
done()
|
done()
|
||||||
|
|
@ -85,9 +85,9 @@ o.spec("promise", function() {
|
||||||
})
|
})
|
||||||
o("resolves asynchronously", function(done) {
|
o("resolves asynchronously", function(done) {
|
||||||
var state = 0
|
var state = 0
|
||||||
|
|
||||||
var promise = Promise.resolve()
|
var promise = Promise.resolve()
|
||||||
|
|
||||||
state = 1
|
state = 1
|
||||||
promise.then(function(value) {
|
promise.then(function(value) {
|
||||||
o(state).equals(2)
|
o(state).equals(2)
|
||||||
|
|
@ -97,7 +97,7 @@ o.spec("promise", function() {
|
||||||
})
|
})
|
||||||
o("resolves via static method", function(done) {
|
o("resolves via static method", function(done) {
|
||||||
var promise = Promise.resolve(1)
|
var promise = Promise.resolve(1)
|
||||||
|
|
||||||
promise.then(function(value) {
|
promise.then(function(value) {
|
||||||
o(value).equals(1)
|
o(value).equals(1)
|
||||||
done()
|
done()
|
||||||
|
|
@ -107,7 +107,7 @@ o.spec("promise", function() {
|
||||||
var promise = new Promise(function(resolve, reject) {
|
var promise = new Promise(function(resolve, reject) {
|
||||||
callAsync(function() {resolve(1)})
|
callAsync(function() {resolve(1)})
|
||||||
})
|
})
|
||||||
|
|
||||||
promise.then(function(value) {
|
promise.then(function(value) {
|
||||||
o(value).equals(1)
|
o(value).equals(1)
|
||||||
done()
|
done()
|
||||||
|
|
@ -117,7 +117,7 @@ o.spec("promise", function() {
|
||||||
var promise = Promise.resolve(1)
|
var promise = Promise.resolve(1)
|
||||||
var a = promise.then(function(value) {return value + 1})
|
var a = promise.then(function(value) {return value + 1})
|
||||||
var b = promise.then(function(value) {return value + 2})
|
var b = promise.then(function(value) {return value + 2})
|
||||||
|
|
||||||
a.then(function(aValue) {
|
a.then(function(aValue) {
|
||||||
b.then(function(bValue) {
|
b.then(function(bValue) {
|
||||||
o(aValue).equals(2)
|
o(aValue).equals(2)
|
||||||
|
|
@ -130,12 +130,12 @@ o.spec("promise", function() {
|
||||||
var promise = new Promise(function(resolve) {
|
var promise = new Promise(function(resolve) {
|
||||||
callAsync(function() {resolve(promise)})
|
callAsync(function() {resolve(promise)})
|
||||||
})
|
})
|
||||||
|
|
||||||
promise.then(null, done)
|
promise.then(null, done)
|
||||||
})
|
})
|
||||||
o("non-function onFulfilled is ignored", function(done) {
|
o("non-function onFulfilled is ignored", function(done) {
|
||||||
var promise = Promise.resolve(1)
|
var promise = Promise.resolve(1)
|
||||||
|
|
||||||
promise.then(null, null).then(function(value) {
|
promise.then(null, null).then(function(value) {
|
||||||
o(value).equals(1)
|
o(value).equals(1)
|
||||||
done()
|
done()
|
||||||
|
|
@ -143,7 +143,7 @@ o.spec("promise", function() {
|
||||||
})
|
})
|
||||||
o("non-function onFulfilled is ignored", function(done) {
|
o("non-function onFulfilled is ignored", function(done) {
|
||||||
var promise = Promise.resolve(1)
|
var promise = Promise.resolve(1)
|
||||||
|
|
||||||
promise.then(null).then(function(value) {
|
promise.then(null).then(function(value) {
|
||||||
o(value).equals(1)
|
o(value).equals(1)
|
||||||
done()
|
done()
|
||||||
|
|
@ -158,10 +158,10 @@ o.spec("promise", function() {
|
||||||
reject(2)
|
reject(2)
|
||||||
callAsync(function() {reject(3)})
|
callAsync(function() {reject(3)})
|
||||||
})
|
})
|
||||||
|
|
||||||
promise.then(null, function(value) {
|
promise.then(null, function(value) {
|
||||||
callCount++
|
callCount++
|
||||||
|
|
||||||
o(value).equals(1)
|
o(value).equals(1)
|
||||||
o(callCount).equals(1)
|
o(callCount).equals(1)
|
||||||
done()
|
done()
|
||||||
|
|
@ -173,7 +173,7 @@ o.spec("promise", function() {
|
||||||
resolve(2)
|
resolve(2)
|
||||||
callAsync(function() {resolve(3)})
|
callAsync(function() {resolve(3)})
|
||||||
})
|
})
|
||||||
|
|
||||||
promise.then(null, function(value) {
|
promise.then(null, function(value) {
|
||||||
o(value).equals(1)
|
o(value).equals(1)
|
||||||
done()
|
done()
|
||||||
|
|
@ -181,9 +181,9 @@ o.spec("promise", function() {
|
||||||
})
|
})
|
||||||
o("rejects asynchronously", function(done) {
|
o("rejects asynchronously", function(done) {
|
||||||
var state = 0
|
var state = 0
|
||||||
|
|
||||||
var promise = Promise.reject()
|
var promise = Promise.reject()
|
||||||
|
|
||||||
state = 1
|
state = 1
|
||||||
promise.then(null, function(value) {
|
promise.then(null, function(value) {
|
||||||
o(state).equals(2)
|
o(state).equals(2)
|
||||||
|
|
@ -194,7 +194,7 @@ o.spec("promise", function() {
|
||||||
o("does not catch itself", function(done) {
|
o("does not catch itself", function(done) {
|
||||||
var callCount = 0
|
var callCount = 0
|
||||||
var promise = Promise.resolve().then(function() {throw 1}, function() {callCount++})
|
var promise = Promise.resolve().then(function() {throw 1}, function() {callCount++})
|
||||||
|
|
||||||
promise.then(null, function() {
|
promise.then(null, function() {
|
||||||
o(callCount).equals(0)
|
o(callCount).equals(0)
|
||||||
done()
|
done()
|
||||||
|
|
@ -202,7 +202,7 @@ o.spec("promise", function() {
|
||||||
})
|
})
|
||||||
o("rejects via static method", function(done) {
|
o("rejects via static method", function(done) {
|
||||||
var promise = Promise.reject(1)
|
var promise = Promise.reject(1)
|
||||||
|
|
||||||
promise.then(null, function(value) {
|
promise.then(null, function(value) {
|
||||||
o(value).equals(1)
|
o(value).equals(1)
|
||||||
return value
|
return value
|
||||||
|
|
@ -215,7 +215,7 @@ o.spec("promise", function() {
|
||||||
var promise = new Promise(function(resolve, reject) {
|
var promise = new Promise(function(resolve, reject) {
|
||||||
reject(1)
|
reject(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
promise.then(null, function(value) {
|
promise.then(null, function(value) {
|
||||||
o(value).equals(1)
|
o(value).equals(1)
|
||||||
done()
|
done()
|
||||||
|
|
@ -225,7 +225,7 @@ o.spec("promise", function() {
|
||||||
var promise = new Promise(function(resolve, reject) {
|
var promise = new Promise(function(resolve, reject) {
|
||||||
callAsync(function() {reject(1)})
|
callAsync(function() {reject(1)})
|
||||||
})
|
})
|
||||||
|
|
||||||
promise.then(null, function(value) {
|
promise.then(null, function(value) {
|
||||||
o(value).equals(1)
|
o(value).equals(1)
|
||||||
done()
|
done()
|
||||||
|
|
@ -235,7 +235,7 @@ o.spec("promise", function() {
|
||||||
var promise = new Promise(function(resolve, reject) {
|
var promise = new Promise(function(resolve, reject) {
|
||||||
throw 1
|
throw 1
|
||||||
})
|
})
|
||||||
|
|
||||||
promise.then(null, function(value) {
|
promise.then(null, function(value) {
|
||||||
o(value).equals(1)
|
o(value).equals(1)
|
||||||
done()
|
done()
|
||||||
|
|
@ -243,7 +243,7 @@ o.spec("promise", function() {
|
||||||
})
|
})
|
||||||
o("rejects on fulfillment error", function(done) {
|
o("rejects on fulfillment error", function(done) {
|
||||||
var promise = Promise.resolve()
|
var promise = Promise.resolve()
|
||||||
|
|
||||||
promise.then(function() {
|
promise.then(function() {
|
||||||
throw 1
|
throw 1
|
||||||
}).then(null, function(value) {
|
}).then(null, function(value) {
|
||||||
|
|
@ -253,7 +253,7 @@ o.spec("promise", function() {
|
||||||
})
|
})
|
||||||
o("rejects on rejection error", function(done) {
|
o("rejects on rejection error", function(done) {
|
||||||
var promise = Promise.resolve()
|
var promise = Promise.resolve()
|
||||||
|
|
||||||
promise.then(function() {
|
promise.then(function() {
|
||||||
throw 1
|
throw 1
|
||||||
}).then(null, function() {
|
}).then(null, function() {
|
||||||
|
|
@ -265,7 +265,7 @@ o.spec("promise", function() {
|
||||||
})
|
})
|
||||||
o("non-function onRejected is ignored", function(done) {
|
o("non-function onRejected is ignored", function(done) {
|
||||||
var promise = Promise.reject(1)
|
var promise = Promise.reject(1)
|
||||||
|
|
||||||
promise.then(function() {}, null).then(null, function(value) {
|
promise.then(function() {}, null).then(null, function(value) {
|
||||||
o(value).equals(1)
|
o(value).equals(1)
|
||||||
done()
|
done()
|
||||||
|
|
@ -275,7 +275,7 @@ o.spec("promise", function() {
|
||||||
o.spec("promise absorption", function() {
|
o.spec("promise absorption", function() {
|
||||||
o("absorbs resolved promise via static resolver", function(done) {
|
o("absorbs resolved promise via static resolver", function(done) {
|
||||||
var promise = Promise.resolve(Promise.resolve(1))
|
var promise = Promise.resolve(Promise.resolve(1))
|
||||||
|
|
||||||
promise.then(function(value) {
|
promise.then(function(value) {
|
||||||
o(value).equals(1)
|
o(value).equals(1)
|
||||||
}).then(done)
|
}).then(done)
|
||||||
|
|
@ -285,7 +285,7 @@ o.spec("promise", function() {
|
||||||
var p = Promise.resolve(1)
|
var p = Promise.resolve(1)
|
||||||
resolve(p)
|
resolve(p)
|
||||||
})
|
})
|
||||||
|
|
||||||
promise.then(function(value) {
|
promise.then(function(value) {
|
||||||
o(value).equals(1)
|
o(value).equals(1)
|
||||||
done()
|
done()
|
||||||
|
|
@ -293,7 +293,7 @@ o.spec("promise", function() {
|
||||||
})
|
})
|
||||||
o("absorbs resolved promise on fulfillment", function(done) {
|
o("absorbs resolved promise on fulfillment", function(done) {
|
||||||
var promise = Promise.resolve()
|
var promise = Promise.resolve()
|
||||||
|
|
||||||
promise.then(function() {
|
promise.then(function() {
|
||||||
return Promise.resolve(1)
|
return Promise.resolve(1)
|
||||||
}).then(function(value) {
|
}).then(function(value) {
|
||||||
|
|
@ -303,7 +303,7 @@ o.spec("promise", function() {
|
||||||
})
|
})
|
||||||
o("absorbs rejected promise via static resolver", function(done) {
|
o("absorbs rejected promise via static resolver", function(done) {
|
||||||
var promise = Promise.resolve(Promise.reject(1))
|
var promise = Promise.resolve(Promise.reject(1))
|
||||||
|
|
||||||
promise.then(null, function(value) {
|
promise.then(null, function(value) {
|
||||||
o(value).equals(1)
|
o(value).equals(1)
|
||||||
done()
|
done()
|
||||||
|
|
@ -313,7 +313,7 @@ o.spec("promise", function() {
|
||||||
var promise = new Promise(function(resolve, reject) {
|
var promise = new Promise(function(resolve, reject) {
|
||||||
resolve(Promise.reject(1))
|
resolve(Promise.reject(1))
|
||||||
})
|
})
|
||||||
|
|
||||||
promise.then(null, function(value) {
|
promise.then(null, function(value) {
|
||||||
o(value).equals(1)
|
o(value).equals(1)
|
||||||
done()
|
done()
|
||||||
|
|
@ -321,7 +321,7 @@ o.spec("promise", function() {
|
||||||
})
|
})
|
||||||
o("absorbs rejected promise on fulfillment", function(done) {
|
o("absorbs rejected promise on fulfillment", function(done) {
|
||||||
var promise = Promise.resolve()
|
var promise = Promise.resolve()
|
||||||
|
|
||||||
promise.then(function() {
|
promise.then(function() {
|
||||||
return Promise.reject(1)
|
return Promise.reject(1)
|
||||||
}).then(null, function(value) {
|
}).then(null, function(value) {
|
||||||
|
|
@ -334,7 +334,7 @@ o.spec("promise", function() {
|
||||||
setTimeout(function() {resolve(1)}, 10)
|
setTimeout(function() {resolve(1)}, 10)
|
||||||
})
|
})
|
||||||
var promise = Promise.resolve(pending)
|
var promise = Promise.resolve(pending)
|
||||||
|
|
||||||
promise.then(function(value) {
|
promise.then(function(value) {
|
||||||
o(value).equals(1)
|
o(value).equals(1)
|
||||||
done()
|
done()
|
||||||
|
|
@ -347,7 +347,7 @@ o.spec("promise", function() {
|
||||||
var promise = new Promise(function(resolve, reject) {
|
var promise = new Promise(function(resolve, reject) {
|
||||||
resolve(pending)
|
resolve(pending)
|
||||||
})
|
})
|
||||||
|
|
||||||
promise.then(function(value) {
|
promise.then(function(value) {
|
||||||
o(value).equals(1)
|
o(value).equals(1)
|
||||||
done()
|
done()
|
||||||
|
|
@ -358,7 +358,7 @@ o.spec("promise", function() {
|
||||||
setTimeout(function() {resolve(1)}, 10)
|
setTimeout(function() {resolve(1)}, 10)
|
||||||
})
|
})
|
||||||
var promise = Promise.resolve()
|
var promise = Promise.resolve()
|
||||||
|
|
||||||
promise.then(function() {
|
promise.then(function() {
|
||||||
return pending
|
return pending
|
||||||
}).then(function(value) {
|
}).then(function(value) {
|
||||||
|
|
@ -371,7 +371,7 @@ o.spec("promise", function() {
|
||||||
setTimeout(function() {reject(1)}, 10)
|
setTimeout(function() {reject(1)}, 10)
|
||||||
})
|
})
|
||||||
var promise = Promise.resolve(pending)
|
var promise = Promise.resolve(pending)
|
||||||
|
|
||||||
promise.then(null, function(value) {
|
promise.then(null, function(value) {
|
||||||
o(value).equals(1)
|
o(value).equals(1)
|
||||||
done()
|
done()
|
||||||
|
|
@ -384,7 +384,7 @@ o.spec("promise", function() {
|
||||||
var promise = new Promise(function(resolve, reject) {
|
var promise = new Promise(function(resolve, reject) {
|
||||||
resolve(pending)
|
resolve(pending)
|
||||||
})
|
})
|
||||||
|
|
||||||
promise.then(null, function(value) {
|
promise.then(null, function(value) {
|
||||||
o(value).equals(1)
|
o(value).equals(1)
|
||||||
done()
|
done()
|
||||||
|
|
@ -395,7 +395,7 @@ o.spec("promise", function() {
|
||||||
setTimeout(function() {reject(1)}, 10)
|
setTimeout(function() {reject(1)}, 10)
|
||||||
})
|
})
|
||||||
var promise = Promise.resolve()
|
var promise = Promise.resolve()
|
||||||
|
|
||||||
promise.then(function() {
|
promise.then(function() {
|
||||||
return pending
|
return pending
|
||||||
}).then(null, function(value) {
|
}).then(null, function(value) {
|
||||||
|
|
@ -405,7 +405,7 @@ o.spec("promise", function() {
|
||||||
})
|
})
|
||||||
o("does not absorb resolved promise via static rejector", function(done) {
|
o("does not absorb resolved promise via static rejector", function(done) {
|
||||||
var promise = Promise.reject(Promise.resolve(1))
|
var promise = Promise.reject(Promise.resolve(1))
|
||||||
|
|
||||||
promise.then(null, function(value) {
|
promise.then(null, function(value) {
|
||||||
o(value instanceof Promise).equals(true)
|
o(value instanceof Promise).equals(true)
|
||||||
done()
|
done()
|
||||||
|
|
@ -415,7 +415,7 @@ o.spec("promise", function() {
|
||||||
var rejected = Promise.reject(1)
|
var rejected = Promise.reject(1)
|
||||||
rejected.catch(function() {})
|
rejected.catch(function() {})
|
||||||
var promise = Promise.reject(rejected)
|
var promise = Promise.reject(rejected)
|
||||||
|
|
||||||
promise.then(null, function(value) {
|
promise.then(null, function(value) {
|
||||||
o(value instanceof Promise).equals(true)
|
o(value instanceof Promise).equals(true)
|
||||||
done()
|
done()
|
||||||
|
|
@ -425,7 +425,7 @@ o.spec("promise", function() {
|
||||||
var promise = new Promise(function(resolve, reject) {
|
var promise = new Promise(function(resolve, reject) {
|
||||||
reject(Promise.resolve(1))
|
reject(Promise.resolve(1))
|
||||||
})
|
})
|
||||||
|
|
||||||
promise.then(null, function(value) {
|
promise.then(null, function(value) {
|
||||||
o(value instanceof Promise).equals(true)
|
o(value instanceof Promise).equals(true)
|
||||||
done()
|
done()
|
||||||
|
|
@ -437,7 +437,7 @@ o.spec("promise", function() {
|
||||||
rejected.catch(function() {})
|
rejected.catch(function() {})
|
||||||
reject(rejected)
|
reject(rejected)
|
||||||
})
|
})
|
||||||
|
|
||||||
promise.then(null, function(value) {
|
promise.then(null, function(value) {
|
||||||
o(value instanceof Promise).equals(true)
|
o(value instanceof Promise).equals(true)
|
||||||
done()
|
done()
|
||||||
|
|
@ -445,7 +445,7 @@ o.spec("promise", function() {
|
||||||
})
|
})
|
||||||
o("does not absorb resolved promise on fulfillment error", function(done) {
|
o("does not absorb resolved promise on fulfillment error", function(done) {
|
||||||
var promise = Promise.resolve()
|
var promise = Promise.resolve()
|
||||||
|
|
||||||
promise.then(function() {
|
promise.then(function() {
|
||||||
throw Promise.resolve(1)
|
throw Promise.resolve(1)
|
||||||
}).then(null, function(value) {
|
}).then(null, function(value) {
|
||||||
|
|
@ -455,7 +455,7 @@ o.spec("promise", function() {
|
||||||
})
|
})
|
||||||
o("does not absorb rejected promise on fulfillment error", function(done) {
|
o("does not absorb rejected promise on fulfillment error", function(done) {
|
||||||
var promise = Promise.resolve()
|
var promise = Promise.resolve()
|
||||||
|
|
||||||
promise.then(function() {
|
promise.then(function() {
|
||||||
var rejected = Promise.reject(1)
|
var rejected = Promise.reject(1)
|
||||||
rejected.catch(function() {})
|
rejected.catch(function() {})
|
||||||
|
|
@ -468,7 +468,7 @@ o.spec("promise", function() {
|
||||||
o("promise stays pending if absorbed promise is pending", function(done) {
|
o("promise stays pending if absorbed promise is pending", function(done) {
|
||||||
var promise = new Promise(function(resolve) {resolve()})
|
var promise = new Promise(function(resolve) {resolve()})
|
||||||
var fulfilled = false, rejected = false
|
var fulfilled = false, rejected = false
|
||||||
|
|
||||||
promise.then(function() {
|
promise.then(function() {
|
||||||
return new Promise(function() {})
|
return new Promise(function() {})
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
|
|
@ -476,7 +476,7 @@ o.spec("promise", function() {
|
||||||
}, function() {
|
}, function() {
|
||||||
rejected = false
|
rejected = false
|
||||||
})
|
})
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
o(fulfilled).equals(false)
|
o(fulfilled).equals(false)
|
||||||
o(rejected).equals(false)
|
o(rejected).equals(false)
|
||||||
|
|
@ -490,7 +490,7 @@ o.spec("promise", function() {
|
||||||
resolve(resolved)
|
resolve(resolved)
|
||||||
}, 10)
|
}, 10)
|
||||||
})
|
})
|
||||||
|
|
||||||
promise.then(function(value) {
|
promise.then(function(value) {
|
||||||
o(value).equals(1)
|
o(value).equals(1)
|
||||||
done()
|
done()
|
||||||
|
|
@ -573,7 +573,7 @@ o.spec("promise", function() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
promise.then(function(value) {
|
promise.then(function(value) {
|
||||||
o(readCount).equals(1)
|
o(readCount).equals(1)
|
||||||
done()
|
done()
|
||||||
|
|
@ -590,7 +590,7 @@ o.spec("promise", function() {
|
||||||
res(1)
|
res(1)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
promise.then(function(value) {
|
promise.then(function(value) {
|
||||||
o(value).equals(2)
|
o(value).equals(2)
|
||||||
done()
|
done()
|
||||||
|
|
@ -605,11 +605,11 @@ o.spec("promise", function() {
|
||||||
})
|
})
|
||||||
throw 3
|
throw 3
|
||||||
})
|
})
|
||||||
|
|
||||||
promise.then(null, function(value) {
|
promise.then(null, function(value) {
|
||||||
o(value).equals(2)
|
o(value).equals(2)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,13 @@
|
||||||
|
|
||||||
module.exports = function(object) {
|
module.exports = function(object) {
|
||||||
if (Object.prototype.toString.call(object) !== "[object Object]") return ""
|
if (Object.prototype.toString.call(object) !== "[object Object]") return ""
|
||||||
|
|
||||||
var args = []
|
var args = []
|
||||||
for (var key in object) {
|
for (var key in object) {
|
||||||
destructure(key, object[key])
|
destructure(key, object[key])
|
||||||
}
|
}
|
||||||
return args.join("&")
|
return args.join("&")
|
||||||
|
|
||||||
function destructure(key, value) {
|
function destructure(key, value) {
|
||||||
if (value instanceof Array) {
|
if (value instanceof Array) {
|
||||||
for (var i = 0; i < value.length; i++) {
|
for (var i = 0; i < value.length; i++) {
|
||||||
|
|
@ -22,4 +22,4 @@ module.exports = function(object) {
|
||||||
}
|
}
|
||||||
else args.push(encodeURIComponent(key) + (value != null && value !== "" ? "=" + encodeURIComponent(value) : ""))
|
else args.push(encodeURIComponent(key) + (value != null && value !== "" ? "=" + encodeURIComponent(value) : ""))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,13 @@
|
||||||
module.exports = function(string) {
|
module.exports = function(string) {
|
||||||
if (string === "" || string == null) return {}
|
if (string === "" || string == null) return {}
|
||||||
if (string.charAt(0) === "?") string = string.slice(1)
|
if (string.charAt(0) === "?") string = string.slice(1)
|
||||||
|
|
||||||
var entries = string.split("&"), data = {}, counters = {}
|
var entries = string.split("&"), data = {}, counters = {}
|
||||||
for (var i = 0; i < entries.length; i++) {
|
for (var i = 0; i < entries.length; i++) {
|
||||||
var entry = entries[i].split("=")
|
var entry = entries[i].split("=")
|
||||||
var key = decodeURIComponent(entry[0])
|
var key = decodeURIComponent(entry[0])
|
||||||
var value = entry.length === 2 ? decodeURIComponent(entry[1]) : ""
|
var value = entry.length === 2 ? decodeURIComponent(entry[1]) : ""
|
||||||
|
|
||||||
//TODO refactor out
|
//TODO refactor out
|
||||||
var number = Number(value)
|
var number = Number(value)
|
||||||
if (value !== "" && !isNaN(number) || value === "NaN") value = number
|
if (value !== "" && !isNaN(number) || value === "NaN") value = number
|
||||||
|
|
@ -19,7 +19,7 @@ module.exports = function(string) {
|
||||||
var date = new Date(value)
|
var date = new Date(value)
|
||||||
if (!isNaN(date.getTime())) value = date
|
if (!isNaN(date.getTime())) value = date
|
||||||
}
|
}
|
||||||
|
|
||||||
var levels = key.split(/\]\[?|\[/)
|
var levels = key.split(/\]\[?|\[/)
|
||||||
var cursor = data
|
var cursor = data
|
||||||
if (key.indexOf("[") > -1) levels.pop()
|
if (key.indexOf("[") > -1) levels.pop()
|
||||||
|
|
@ -39,4 +39,4 @@ module.exports = function(string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
<script src="../../querystring/build.js"></script>
|
<script src="../../querystring/build.js"></script>
|
||||||
<script src="test-parseQueryString.js"></script>
|
<script src="test-parseQueryString.js"></script>
|
||||||
<script src="test-buildQueryString.js"></script>
|
<script src="test-buildQueryString.js"></script>
|
||||||
|
|
||||||
<script>require("../../ospec/ospec").run()</script>
|
<script>require("../../ospec/ospec").run()</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
|
|
@ -6,77 +6,77 @@ var buildQueryString = require("../../querystring/build")
|
||||||
o.spec("buildQueryString", function() {
|
o.spec("buildQueryString", function() {
|
||||||
o("handles flat object", function() {
|
o("handles flat object", function() {
|
||||||
var string = buildQueryString({a: "b", c: 1})
|
var string = buildQueryString({a: "b", c: 1})
|
||||||
|
|
||||||
o(string).equals("a=b&c=1")
|
o(string).equals("a=b&c=1")
|
||||||
})
|
})
|
||||||
o("handles escaped values", function() {
|
o("handles escaped values", function() {
|
||||||
var data = buildQueryString({";:@&=+$,/?%#": ";:@&=+$,/?%#"})
|
var data = buildQueryString({";:@&=+$,/?%#": ";:@&=+$,/?%#"})
|
||||||
|
|
||||||
o(data).equals("%3B%3A%40%26%3D%2B%24%2C%2F%3F%25%23=%3B%3A%40%26%3D%2B%24%2C%2F%3F%25%23")
|
o(data).equals("%3B%3A%40%26%3D%2B%24%2C%2F%3F%25%23=%3B%3A%40%26%3D%2B%24%2C%2F%3F%25%23")
|
||||||
})
|
})
|
||||||
o("handles unicode", function() {
|
o("handles unicode", function() {
|
||||||
var data = buildQueryString({"ö": "ö"})
|
var data = buildQueryString({"ö": "ö"})
|
||||||
|
|
||||||
o(data).equals("%C3%B6=%C3%B6")
|
o(data).equals("%C3%B6=%C3%B6")
|
||||||
})
|
})
|
||||||
o("handles nested object", function() {
|
o("handles nested object", function() {
|
||||||
var string = buildQueryString({a: {b: 1, c: 2}})
|
var string = buildQueryString({a: {b: 1, c: 2}})
|
||||||
|
|
||||||
o(string).equals("a%5Bb%5D=1&a%5Bc%5D=2")
|
o(string).equals("a%5Bb%5D=1&a%5Bc%5D=2")
|
||||||
})
|
})
|
||||||
o("handles deep nested object", function() {
|
o("handles deep nested object", function() {
|
||||||
var string = buildQueryString({a: {b: {c: 1, d: 2}}})
|
var string = buildQueryString({a: {b: {c: 1, d: 2}}})
|
||||||
|
|
||||||
o(string).equals("a%5Bb%5D%5Bc%5D=1&a%5Bb%5D%5Bd%5D=2")
|
o(string).equals("a%5Bb%5D%5Bc%5D=1&a%5Bb%5D%5Bd%5D=2")
|
||||||
})
|
})
|
||||||
o("handles nested array", function() {
|
o("handles nested array", function() {
|
||||||
var string = buildQueryString({a: ["x", "y"]})
|
var string = buildQueryString({a: ["x", "y"]})
|
||||||
|
|
||||||
o(string).equals("a%5B0%5D=x&a%5B1%5D=y")
|
o(string).equals("a%5B0%5D=x&a%5B1%5D=y")
|
||||||
})
|
})
|
||||||
o("handles deep nested array", function() {
|
o("handles deep nested array", function() {
|
||||||
var string = buildQueryString({a: [["x", "y"]]})
|
var string = buildQueryString({a: [["x", "y"]]})
|
||||||
|
|
||||||
o(string).equals("a%5B0%5D%5B0%5D=x&a%5B0%5D%5B1%5D=y")
|
o(string).equals("a%5B0%5D%5B0%5D=x&a%5B0%5D%5B1%5D=y")
|
||||||
})
|
})
|
||||||
o("handles deep nested array in object", function() {
|
o("handles deep nested array in object", function() {
|
||||||
var string = buildQueryString({a: {b: ["x", "y"]}})
|
var string = buildQueryString({a: {b: ["x", "y"]}})
|
||||||
|
|
||||||
o(string).equals("a%5Bb%5D%5B0%5D=x&a%5Bb%5D%5B1%5D=y")
|
o(string).equals("a%5Bb%5D%5B0%5D=x&a%5Bb%5D%5B1%5D=y")
|
||||||
})
|
})
|
||||||
o("handles deep nested object in array", function() {
|
o("handles deep nested object in array", function() {
|
||||||
var string = buildQueryString({a: [{b: 1, c: 2}]})
|
var string = buildQueryString({a: [{b: 1, c: 2}]})
|
||||||
|
|
||||||
o(string).equals("a%5B0%5D%5Bb%5D=1&a%5B0%5D%5Bc%5D=2")
|
o(string).equals("a%5B0%5D%5Bb%5D=1&a%5B0%5D%5Bc%5D=2")
|
||||||
})
|
})
|
||||||
o("handles date", function() {
|
o("handles date", function() {
|
||||||
var string = buildQueryString({a: new Date(0)})
|
var string = buildQueryString({a: new Date(0)})
|
||||||
|
|
||||||
o(string).equals("a=" + encodeURIComponent(new Date(0).toString()))
|
o(string).equals("a=" + encodeURIComponent(new Date(0).toString()))
|
||||||
})
|
})
|
||||||
o("turns null into value-less string (like jQuery)", function() {
|
o("turns null into value-less string (like jQuery)", function() {
|
||||||
var string = buildQueryString({a: null})
|
var string = buildQueryString({a: null})
|
||||||
|
|
||||||
o(string).equals("a")
|
o(string).equals("a")
|
||||||
})
|
})
|
||||||
o("turns undefined into value-less string (like jQuery)", function() {
|
o("turns undefined into value-less string (like jQuery)", function() {
|
||||||
var string = buildQueryString({a: undefined})
|
var string = buildQueryString({a: undefined})
|
||||||
|
|
||||||
o(string).equals("a")
|
o(string).equals("a")
|
||||||
})
|
})
|
||||||
o("turns empty string into value-less string (like jQuery)", function() {
|
o("turns empty string into value-less string (like jQuery)", function() {
|
||||||
var string = buildQueryString({a: ""})
|
var string = buildQueryString({a: ""})
|
||||||
|
|
||||||
o(string).equals("a")
|
o(string).equals("a")
|
||||||
})
|
})
|
||||||
o("handles zero", function() {
|
o("handles zero", function() {
|
||||||
var string = buildQueryString({a: 0})
|
var string = buildQueryString({a: 0})
|
||||||
|
|
||||||
o(string).equals("a=0")
|
o(string).equals("a=0")
|
||||||
})
|
})
|
||||||
o("handles false", function() {
|
o("handles false", function() {
|
||||||
var string = buildQueryString({a: false})
|
var string = buildQueryString({a: false})
|
||||||
|
|
||||||
o(string).equals("a=false")
|
o(string).equals("a=false")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ function hyperscript(selector) {
|
||||||
}
|
}
|
||||||
if (children instanceof Array && children.length == 1 && children[0] != null && children[0].tag === "#") text = children[0].children
|
if (children instanceof Array && children.length == 1 && children[0] != null && children[0].tag === "#") text = children[0].children
|
||||||
else childList = children
|
else childList = children
|
||||||
|
|
||||||
return Node(tag || "div", attrs.key, hasAttrs ? attrs : undefined, childList, text, undefined)
|
return Node(tag || "div", attrs.key, hasAttrs ? attrs : undefined, childList, text, undefined)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -57,9 +57,9 @@ function hyperscript(selector) {
|
||||||
children = []
|
children = []
|
||||||
for (var i = childrenIndex; i < arguments.length; i++) children.push(arguments[i])
|
for (var i = childrenIndex; i < arguments.length; i++) children.push(arguments[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof selector === "string") return selectorCache[selector](attrs || {}, Node.normalizeChildren(children))
|
if (typeof selector === "string") return selectorCache[selector](attrs || {}, Node.normalizeChildren(children))
|
||||||
|
|
||||||
return Node(selector, attrs && attrs.key, attrs || {}, Node.normalizeChildren(children), undefined, undefined)
|
return Node(selector, attrs && attrs.key, attrs || {}, Node.normalizeChildren(children), undefined, undefined)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,4 +13,4 @@ Node.normalizeChildren = function normalizeChildren(children) {
|
||||||
return children
|
return children
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Node
|
module.exports = Node
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ module.exports = function($window) {
|
||||||
|
|
||||||
var onevent
|
var onevent
|
||||||
function setEventCallback(callback) {return onevent = callback}
|
function setEventCallback(callback) {return onevent = callback}
|
||||||
|
|
||||||
//create
|
//create
|
||||||
function createNodes(parent, vnodes, start, end, hooks, nextSibling, ns) {
|
function createNodes(parent, vnodes, start, end, hooks, nextSibling, ns) {
|
||||||
for (var i = start; i < end; i++) {
|
for (var i = start; i < end; i++) {
|
||||||
|
|
@ -38,7 +38,7 @@ module.exports = function($window) {
|
||||||
var match = vnode.children.match(/^\s*?<(\w+)/im) || []
|
var match = vnode.children.match(/^\s*?<(\w+)/im) || []
|
||||||
var parent = {caption: "table", thead: "table", tbody: "table", tfoot: "table", tr: "tbody", th: "tr", td: "tr", colgroup: "table", col: "colgroup"}[match[1]] || "div"
|
var parent = {caption: "table", thead: "table", tbody: "table", tfoot: "table", tr: "tbody", th: "tr", td: "tr", colgroup: "table", col: "colgroup"}[match[1]] || "div"
|
||||||
var temp = $doc.createElement(parent)
|
var temp = $doc.createElement(parent)
|
||||||
|
|
||||||
temp.innerHTML = vnode.children
|
temp.innerHTML = vnode.children
|
||||||
vnode.dom = temp.firstChild
|
vnode.dom = temp.firstChild
|
||||||
vnode.domSize = temp.childNodes.length
|
vnode.domSize = temp.childNodes.length
|
||||||
|
|
@ -65,24 +65,24 @@ module.exports = function($window) {
|
||||||
case "svg": ns = "http://www.w3.org/2000/svg"; break
|
case "svg": ns = "http://www.w3.org/2000/svg"; break
|
||||||
case "math": ns = "http://www.w3.org/1998/Math/MathML"; break
|
case "math": ns = "http://www.w3.org/1998/Math/MathML"; break
|
||||||
}
|
}
|
||||||
|
|
||||||
var attrs = vnode.attrs
|
var attrs = vnode.attrs
|
||||||
var is = attrs && attrs.is
|
var is = attrs && attrs.is
|
||||||
|
|
||||||
var element = ns ?
|
var element = ns ?
|
||||||
is ? $doc.createElementNS(ns, tag, is) : $doc.createElementNS(ns, tag) :
|
is ? $doc.createElementNS(ns, tag, is) : $doc.createElementNS(ns, tag) :
|
||||||
is ? $doc.createElement(tag, is) : $doc.createElement(tag)
|
is ? $doc.createElement(tag, is) : $doc.createElement(tag)
|
||||||
vnode.dom = element
|
vnode.dom = element
|
||||||
|
|
||||||
if (attrs != null) {
|
if (attrs != null) {
|
||||||
setAttrs(vnode, attrs, ns)
|
setAttrs(vnode, attrs, ns)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vnode.text != null) {
|
if (vnode.text != null) {
|
||||||
if (vnode.text !== "") element.textContent = vnode.text
|
if (vnode.text !== "") element.textContent = vnode.text
|
||||||
else vnode.children = [Node("#", undefined, undefined, vnode.text, undefined, undefined)]
|
else vnode.children = [Node("#", undefined, undefined, vnode.text, undefined, undefined)]
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vnode.children != null) {
|
if (vnode.children != null) {
|
||||||
var children = vnode.children
|
var children = vnode.children
|
||||||
createNodes(element, children, 0, children.length, hooks, null, ns)
|
createNodes(element, children, 0, children.length, hooks, null, ns)
|
||||||
|
|
@ -92,7 +92,7 @@ module.exports = function($window) {
|
||||||
}
|
}
|
||||||
function createComponent(vnode, hooks, ns) {
|
function createComponent(vnode, hooks, ns) {
|
||||||
vnode.state = copy(vnode.tag)
|
vnode.state = copy(vnode.tag)
|
||||||
|
|
||||||
initLifecycle(vnode.tag, vnode, hooks)
|
initLifecycle(vnode.tag, vnode, hooks)
|
||||||
vnode.instance = Node.normalize(vnode.tag.view.call(vnode.state, vnode))
|
vnode.instance = Node.normalize(vnode.tag.view.call(vnode.state, vnode))
|
||||||
if (vnode.instance != null) {
|
if (vnode.instance != null) {
|
||||||
|
|
@ -112,7 +112,7 @@ module.exports = function($window) {
|
||||||
else {
|
else {
|
||||||
var recycling = isRecyclable(old, vnodes)
|
var recycling = isRecyclable(old, vnodes)
|
||||||
if (recycling) old = old.concat(old.pool)
|
if (recycling) old = old.concat(old.pool)
|
||||||
|
|
||||||
var oldStart = 0, start = 0, oldEnd = old.length - 1, end = vnodes.length - 1, map
|
var oldStart = 0, start = 0, oldEnd = old.length - 1, end = vnodes.length - 1, map
|
||||||
while (oldEnd >= oldStart && end >= start) {
|
while (oldEnd >= oldStart && end >= start) {
|
||||||
var o = old[oldStart], v = vnodes[start]
|
var o = old[oldStart], v = vnodes[start]
|
||||||
|
|
@ -321,7 +321,7 @@ module.exports = function($window) {
|
||||||
}
|
}
|
||||||
if (expected > 0) return
|
if (expected > 0) return
|
||||||
}
|
}
|
||||||
|
|
||||||
onremove(vnode)
|
onremove(vnode)
|
||||||
if (vnode.dom) {
|
if (vnode.dom) {
|
||||||
var count = vnode.domSize || 1
|
var count = vnode.domSize || 1
|
||||||
|
|
@ -341,7 +341,7 @@ module.exports = function($window) {
|
||||||
function onremove(vnode) {
|
function onremove(vnode) {
|
||||||
if (vnode.attrs && vnode.attrs.onremove) vnode.attrs.onremove.call(vnode.state, vnode)
|
if (vnode.attrs && vnode.attrs.onremove) vnode.attrs.onremove.call(vnode.state, vnode)
|
||||||
if (typeof vnode.tag !== "string" && vnode.tag.onremove) vnode.tag.onremove.call(vnode.state, vnode)
|
if (typeof vnode.tag !== "string" && vnode.tag.onremove) vnode.tag.onremove.call(vnode.state, vnode)
|
||||||
|
|
||||||
var children = vnode.children
|
var children = vnode.children
|
||||||
if (children instanceof Array) {
|
if (children instanceof Array) {
|
||||||
for (var i = 0; i < children.length; i++) {
|
for (var i = 0; i < children.length; i++) {
|
||||||
|
|
@ -412,7 +412,7 @@ module.exports = function($window) {
|
||||||
function hasIntegrationMethods(source) {
|
function hasIntegrationMethods(source) {
|
||||||
return source != null && (source.oncreate || source.onupdate || source.onbeforeremove || source.onremove)
|
return source != null && (source.oncreate || source.onupdate || source.onbeforeremove || source.onremove)
|
||||||
}
|
}
|
||||||
|
|
||||||
//style
|
//style
|
||||||
function updateStyle(element, old, style) {
|
function updateStyle(element, old, style) {
|
||||||
if (old === style) element.style = "", old = null
|
if (old === style) element.style = "", old = null
|
||||||
|
|
@ -430,7 +430,7 @@ module.exports = function($window) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//event
|
//event
|
||||||
function updateEvent(vnode, key, value) {
|
function updateEvent(vnode, key, value) {
|
||||||
var element = vnode.dom
|
var element = vnode.dom
|
||||||
|
|
@ -470,7 +470,7 @@ module.exports = function($window) {
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
function copy(data) {
|
function copy(data) {
|
||||||
if (data instanceof Array) {
|
if (data instanceof Array) {
|
||||||
var output = []
|
var output = []
|
||||||
|
|
@ -489,7 +489,7 @@ module.exports = function($window) {
|
||||||
var hooks = []
|
var hooks = []
|
||||||
var active = $doc.activeElement
|
var active = $doc.activeElement
|
||||||
if (dom.vnodes == null) dom.vnodes = []
|
if (dom.vnodes == null) dom.vnodes = []
|
||||||
|
|
||||||
if (!(vnodes instanceof Array)) vnodes = [vnodes]
|
if (!(vnodes instanceof Array)) vnodes = [vnodes]
|
||||||
updateNodes(dom, dom.vnodes, Node.normalizeChildren(vnodes), hooks, null, undefined)
|
updateNodes(dom, dom.vnodes, Node.normalizeChildren(vnodes), hooks, null, undefined)
|
||||||
for (var i = 0; i < hooks.length; i++) hooks[i]()
|
for (var i = 0; i < hooks.length; i++) hooks[i]()
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@
|
||||||
<script src="test-input.js"></script>
|
<script src="test-input.js"></script>
|
||||||
<script src="test-textContent.js"></script>
|
<script src="test-textContent.js"></script>
|
||||||
<script src="test-component.js"></script>
|
<script src="test-component.js"></script>
|
||||||
|
|
||||||
<script>require("../../ospec/ospec").run()</script>
|
<script>require("../../ospec/ospec").run()</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
|
|
@ -15,47 +15,47 @@ o.spec("attributes", function() {
|
||||||
o.spec("input readonly", function() {
|
o.spec("input readonly", function() {
|
||||||
o("when input readonly is true, attribute is present", function() {
|
o("when input readonly is true, attribute is present", function() {
|
||||||
var a = {tag: "input", attrs: {readonly: true}}
|
var a = {tag: "input", attrs: {readonly: true}}
|
||||||
|
|
||||||
render(root, [a])
|
render(root, [a])
|
||||||
|
|
||||||
o(a.dom.attributes["readonly"].nodeValue).equals("")
|
o(a.dom.attributes["readonly"].nodeValue).equals("")
|
||||||
})
|
})
|
||||||
o("when input readonly is false, attribute is not present", function() {
|
o("when input readonly is false, attribute is not present", function() {
|
||||||
var a = {tag: "input", attrs: {readonly: false}}
|
var a = {tag: "input", attrs: {readonly: false}}
|
||||||
|
|
||||||
render(root, [a])
|
render(root, [a])
|
||||||
|
|
||||||
o(a.dom.attributes["readonly"]).equals(undefined)
|
o(a.dom.attributes["readonly"]).equals(undefined)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
o.spec("input checked", function() {
|
o.spec("input checked", function() {
|
||||||
o("when input checked is true, attribute is not present", function() {
|
o("when input checked is true, attribute is not present", function() {
|
||||||
var a = {tag: "input", attrs: {checked: true}}
|
var a = {tag: "input", attrs: {checked: true}}
|
||||||
|
|
||||||
render(root, [a])
|
render(root, [a])
|
||||||
|
|
||||||
o(a.dom.checked).equals(true)
|
o(a.dom.checked).equals(true)
|
||||||
o(a.dom.attributes["checked"]).equals(undefined)
|
o(a.dom.attributes["checked"]).equals(undefined)
|
||||||
})
|
})
|
||||||
o("when input checked is false, attribute is not present", function() {
|
o("when input checked is false, attribute is not present", function() {
|
||||||
var a = {tag: "input", attrs: {checked: false}}
|
var a = {tag: "input", attrs: {checked: false}}
|
||||||
|
|
||||||
render(root, [a])
|
render(root, [a])
|
||||||
|
|
||||||
o(a.dom.checked).equals(false)
|
o(a.dom.checked).equals(false)
|
||||||
o(a.dom.attributes["checked"]).equals(undefined)
|
o(a.dom.attributes["checked"]).equals(undefined)
|
||||||
})
|
})
|
||||||
o("after input checked is changed by 3rd party, it can still be changed by render", function() {
|
o("after input checked is changed by 3rd party, it can still be changed by render", function() {
|
||||||
var a = {tag: "input", attrs: {checked: false}}
|
var a = {tag: "input", attrs: {checked: false}}
|
||||||
var b = {tag: "input", attrs: {checked: true}}
|
var b = {tag: "input", attrs: {checked: true}}
|
||||||
|
|
||||||
render(root, [a])
|
render(root, [a])
|
||||||
|
|
||||||
a.dom.checked = true //setting the javascript property makes the value no longer track the state of the attribute
|
a.dom.checked = true //setting the javascript property makes the value no longer track the state of the attribute
|
||||||
a.dom.checked = false
|
a.dom.checked = false
|
||||||
|
|
||||||
render(root, [b])
|
render(root, [b])
|
||||||
|
|
||||||
o(a.dom.checked).equals(true)
|
o(a.dom.checked).equals(true)
|
||||||
o(a.dom.attributes["checked"]).equals(undefined)
|
o(a.dom.attributes["checked"]).equals(undefined)
|
||||||
})
|
})
|
||||||
|
|
@ -63,16 +63,16 @@ o.spec("attributes", function() {
|
||||||
o.spec("link href", function() {
|
o.spec("link href", function() {
|
||||||
o("when link href is true, attribute is present", function() {
|
o("when link href is true, attribute is present", function() {
|
||||||
var a = {tag: "a", attrs: {href: true}}
|
var a = {tag: "a", attrs: {href: true}}
|
||||||
|
|
||||||
render(root, [a])
|
render(root, [a])
|
||||||
|
|
||||||
o(a.dom.attributes["href"]).notEquals(undefined)
|
o(a.dom.attributes["href"]).notEquals(undefined)
|
||||||
})
|
})
|
||||||
o("when link href is false, attribute is not present", function() {
|
o("when link href is false, attribute is not present", function() {
|
||||||
var a = {tag: "a", attrs: {href: false}}
|
var a = {tag: "a", attrs: {href: false}}
|
||||||
|
|
||||||
render(root, [a])
|
render(root, [a])
|
||||||
|
|
||||||
o(a.dom.attributes["href"]).equals(undefined)
|
o(a.dom.attributes["href"]).equals(undefined)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
@ -85,4 +85,4 @@ o.spec("attributes", function() {
|
||||||
o(a.dom.attributes["class"].nodeValue).equals("test")
|
o(a.dom.attributes["class"].nodeValue).equals("test")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,9 @@ o.spec("component", function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var node = {tag: component}
|
var node = {tag: component}
|
||||||
|
|
||||||
render(root, [node])
|
render(root, [node])
|
||||||
|
|
||||||
o(root.firstChild.nodeName).equals("DIV")
|
o(root.firstChild.nodeName).equals("DIV")
|
||||||
o(root.firstChild.attributes["id"].nodeValue).equals("a")
|
o(root.firstChild.attributes["id"].nodeValue).equals("a")
|
||||||
o(root.firstChild.firstChild.nodeValue).equals("b")
|
o(root.firstChild.firstChild.nodeValue).equals("b")
|
||||||
|
|
@ -34,9 +34,9 @@ o.spec("component", function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var node = {tag: component, attrs: {id: "a"}, text: "b"}
|
var node = {tag: component, attrs: {id: "a"}, text: "b"}
|
||||||
|
|
||||||
render(root, [node])
|
render(root, [node])
|
||||||
|
|
||||||
o(root.firstChild.nodeName).equals("DIV")
|
o(root.firstChild.nodeName).equals("DIV")
|
||||||
o(root.firstChild.attributes["id"].nodeValue).equals("a")
|
o(root.firstChild.attributes["id"].nodeValue).equals("a")
|
||||||
o(root.firstChild.firstChild.nodeValue).equals("b")
|
o(root.firstChild.firstChild.nodeValue).equals("b")
|
||||||
|
|
@ -49,7 +49,7 @@ o.spec("component", function() {
|
||||||
}
|
}
|
||||||
render(root, [{tag: component, attrs: {id: "a"}, text: "b"}])
|
render(root, [{tag: component, attrs: {id: "a"}, text: "b"}])
|
||||||
render(root, [{tag: component, attrs: {id: "c"}, text: "d"}])
|
render(root, [{tag: component, attrs: {id: "c"}, text: "d"}])
|
||||||
|
|
||||||
o(root.firstChild.nodeName).equals("DIV")
|
o(root.firstChild.nodeName).equals("DIV")
|
||||||
o(root.firstChild.attributes["id"].nodeValue).equals("c")
|
o(root.firstChild.attributes["id"].nodeValue).equals("c")
|
||||||
o(root.firstChild.firstChild.nodeValue).equals("d")
|
o(root.firstChild.firstChild.nodeValue).equals("d")
|
||||||
|
|
@ -63,7 +63,7 @@ o.spec("component", function() {
|
||||||
var div = {tag: "div", key: 2}
|
var div = {tag: "div", key: 2}
|
||||||
render(root, [{tag: component, key: 1}, div])
|
render(root, [{tag: component, key: 1}, div])
|
||||||
render(root, [{tag: "div", key: 2}])
|
render(root, [{tag: "div", key: 2}])
|
||||||
|
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
o(root.firstChild).equals(div.dom)
|
o(root.firstChild).equals(div.dom)
|
||||||
})
|
})
|
||||||
|
|
@ -74,7 +74,7 @@ o.spec("component", function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
render(root, [{tag: "svg", children: [{tag: component}]}])
|
render(root, [{tag: "svg", children: [{tag: component}]}])
|
||||||
|
|
||||||
o(root.firstChild.firstChild.namespaceURI).equals("http://www.w3.org/2000/svg")
|
o(root.firstChild.firstChild.namespaceURI).equals("http://www.w3.org/2000/svg")
|
||||||
})
|
})
|
||||||
o("svg works when updating across component boundary", function() {
|
o("svg works when updating across component boundary", function() {
|
||||||
|
|
@ -85,7 +85,7 @@ o.spec("component", function() {
|
||||||
}
|
}
|
||||||
render(root, [{tag: "svg", children: [{tag: component}]}])
|
render(root, [{tag: "svg", children: [{tag: component}]}])
|
||||||
render(root, [{tag: "svg", children: [{tag: component}]}])
|
render(root, [{tag: "svg", children: [{tag: component}]}])
|
||||||
|
|
||||||
o(root.firstChild.firstChild.namespaceURI).equals("http://www.w3.org/2000/svg")
|
o(root.firstChild.firstChild.namespaceURI).equals("http://www.w3.org/2000/svg")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
@ -100,7 +100,7 @@ o.spec("component", function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
render(root, [{tag: component}])
|
render(root, [{tag: component}])
|
||||||
|
|
||||||
o(root.childNodes.length).equals(2)
|
o(root.childNodes.length).equals(2)
|
||||||
o(root.childNodes[0].nodeName).equals("LABEL")
|
o(root.childNodes[0].nodeName).equals("LABEL")
|
||||||
o(root.childNodes[1].nodeName).equals("INPUT")
|
o(root.childNodes[1].nodeName).equals("INPUT")
|
||||||
|
|
@ -112,7 +112,7 @@ o.spec("component", function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
render(root, [{tag: component}])
|
render(root, [{tag: component}])
|
||||||
|
|
||||||
o(root.firstChild.nodeType).equals(3)
|
o(root.firstChild.nodeType).equals(3)
|
||||||
o(root.firstChild.nodeValue).equals("a")
|
o(root.firstChild.nodeValue).equals("a")
|
||||||
})
|
})
|
||||||
|
|
@ -123,7 +123,7 @@ o.spec("component", function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
render(root, [{tag: component}])
|
render(root, [{tag: component}])
|
||||||
|
|
||||||
o(root.firstChild.nodeType).equals(3)
|
o(root.firstChild.nodeType).equals(3)
|
||||||
o(root.firstChild.nodeValue).equals("")
|
o(root.firstChild.nodeValue).equals("")
|
||||||
})
|
})
|
||||||
|
|
@ -134,7 +134,7 @@ o.spec("component", function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
render(root, [{tag: component}])
|
render(root, [{tag: component}])
|
||||||
|
|
||||||
o(root.firstChild.nodeType).equals(3)
|
o(root.firstChild.nodeType).equals(3)
|
||||||
o(root.firstChild.nodeValue).equals("1")
|
o(root.firstChild.nodeValue).equals("1")
|
||||||
})
|
})
|
||||||
|
|
@ -145,7 +145,7 @@ o.spec("component", function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
render(root, [{tag: component}])
|
render(root, [{tag: component}])
|
||||||
|
|
||||||
o(root.firstChild.nodeType).equals(3)
|
o(root.firstChild.nodeType).equals(3)
|
||||||
o(root.firstChild.nodeValue).equals("0")
|
o(root.firstChild.nodeValue).equals("0")
|
||||||
})
|
})
|
||||||
|
|
@ -156,7 +156,7 @@ o.spec("component", function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
render(root, [{tag: component}])
|
render(root, [{tag: component}])
|
||||||
|
|
||||||
o(root.firstChild.nodeType).equals(3)
|
o(root.firstChild.nodeType).equals(3)
|
||||||
o(root.firstChild.nodeValue).equals("true")
|
o(root.firstChild.nodeValue).equals("true")
|
||||||
})
|
})
|
||||||
|
|
@ -167,7 +167,7 @@ o.spec("component", function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
render(root, [{tag: component}])
|
render(root, [{tag: component}])
|
||||||
|
|
||||||
o(root.firstChild.nodeType).equals(3)
|
o(root.firstChild.nodeType).equals(3)
|
||||||
o(root.firstChild.nodeValue).equals("false")
|
o(root.firstChild.nodeValue).equals("false")
|
||||||
})
|
})
|
||||||
|
|
@ -178,7 +178,7 @@ o.spec("component", function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
render(root, [{tag: component}])
|
render(root, [{tag: component}])
|
||||||
|
|
||||||
o(root.childNodes.length).equals(0)
|
o(root.childNodes.length).equals(0)
|
||||||
})
|
})
|
||||||
o("can return undefined", function() {
|
o("can return undefined", function() {
|
||||||
|
|
@ -188,7 +188,7 @@ o.spec("component", function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
render(root, [{tag: component}])
|
render(root, [{tag: component}])
|
||||||
|
|
||||||
o(root.childNodes.length).equals(0)
|
o(root.childNodes.length).equals(0)
|
||||||
})
|
})
|
||||||
o("can update when returning fragments", function() {
|
o("can update when returning fragments", function() {
|
||||||
|
|
@ -202,7 +202,7 @@ o.spec("component", function() {
|
||||||
}
|
}
|
||||||
render(root, [{tag: component}])
|
render(root, [{tag: component}])
|
||||||
render(root, [{tag: component}])
|
render(root, [{tag: component}])
|
||||||
|
|
||||||
o(root.childNodes.length).equals(2)
|
o(root.childNodes.length).equals(2)
|
||||||
o(root.childNodes[0].nodeName).equals("LABEL")
|
o(root.childNodes[0].nodeName).equals("LABEL")
|
||||||
o(root.childNodes[1].nodeName).equals("INPUT")
|
o(root.childNodes[1].nodeName).equals("INPUT")
|
||||||
|
|
@ -215,7 +215,7 @@ o.spec("component", function() {
|
||||||
}
|
}
|
||||||
render(root, [{tag: component}])
|
render(root, [{tag: component}])
|
||||||
render(root, [{tag: component}])
|
render(root, [{tag: component}])
|
||||||
|
|
||||||
o(root.firstChild.nodeType).equals(3)
|
o(root.firstChild.nodeType).equals(3)
|
||||||
o(root.firstChild.nodeValue).equals("a")
|
o(root.firstChild.nodeValue).equals("a")
|
||||||
})
|
})
|
||||||
|
|
@ -227,7 +227,7 @@ o.spec("component", function() {
|
||||||
}
|
}
|
||||||
render(root, [{tag: component}])
|
render(root, [{tag: component}])
|
||||||
render(root, [{tag: component}])
|
render(root, [{tag: component}])
|
||||||
|
|
||||||
o(root.childNodes.length).equals(0)
|
o(root.childNodes.length).equals(0)
|
||||||
})
|
})
|
||||||
o("can remove when returning fragments", function() {
|
o("can remove when returning fragments", function() {
|
||||||
|
|
@ -241,9 +241,9 @@ o.spec("component", function() {
|
||||||
}
|
}
|
||||||
var div = {tag: "div", key: 2}
|
var div = {tag: "div", key: 2}
|
||||||
render(root, [{tag: component, key: 1}, div])
|
render(root, [{tag: component, key: 1}, div])
|
||||||
|
|
||||||
render(root, [{tag: "div", key: 2}])
|
render(root, [{tag: "div", key: 2}])
|
||||||
|
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
o(root.firstChild).equals(div.dom)
|
o(root.firstChild).equals(div.dom)
|
||||||
})
|
})
|
||||||
|
|
@ -255,9 +255,9 @@ o.spec("component", function() {
|
||||||
}
|
}
|
||||||
var div = {tag: "div", key: 2}
|
var div = {tag: "div", key: 2}
|
||||||
render(root, [{tag: component, key: 1}, div])
|
render(root, [{tag: component, key: 1}, div])
|
||||||
|
|
||||||
render(root, [{tag: "div", key: 2}])
|
render(root, [{tag: "div", key: 2}])
|
||||||
|
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
o(root.firstChild).equals(div.dom)
|
o(root.firstChild).equals(div.dom)
|
||||||
})
|
})
|
||||||
|
|
@ -268,7 +268,7 @@ o.spec("component", function() {
|
||||||
var component = {
|
var component = {
|
||||||
oninit: function(vnode) {
|
oninit: function(vnode) {
|
||||||
called++
|
called++
|
||||||
|
|
||||||
o(vnode.tag).equals(component)
|
o(vnode.tag).equals(component)
|
||||||
o(vnode.dom).equals(undefined)
|
o(vnode.dom).equals(undefined)
|
||||||
o(root.childNodes.length).equals(0)
|
o(root.childNodes.length).equals(0)
|
||||||
|
|
@ -278,9 +278,9 @@ o.spec("component", function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var node = {tag: component}
|
var node = {tag: component}
|
||||||
|
|
||||||
render(root, [node])
|
render(root, [node])
|
||||||
|
|
||||||
o(called).equals(1)
|
o(called).equals(1)
|
||||||
o(root.firstChild.nodeName).equals("DIV")
|
o(root.firstChild.nodeName).equals("DIV")
|
||||||
o(root.firstChild.attributes["id"].nodeValue).equals("a")
|
o(root.firstChild.attributes["id"].nodeValue).equals("a")
|
||||||
|
|
@ -291,7 +291,7 @@ o.spec("component", function() {
|
||||||
var component = {
|
var component = {
|
||||||
oninit: function(vnode) {
|
oninit: function(vnode) {
|
||||||
called++
|
called++
|
||||||
|
|
||||||
o(vnode.tag).equals(component)
|
o(vnode.tag).equals(component)
|
||||||
o(vnode.dom).equals(undefined)
|
o(vnode.dom).equals(undefined)
|
||||||
o(root.childNodes.length).equals(0)
|
o(root.childNodes.length).equals(0)
|
||||||
|
|
@ -301,9 +301,9 @@ o.spec("component", function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var node = {tag: component}
|
var node = {tag: component}
|
||||||
|
|
||||||
render(root, [node])
|
render(root, [node])
|
||||||
|
|
||||||
o(called).equals(1)
|
o(called).equals(1)
|
||||||
o(root.firstChild.nodeName).equals("DIV")
|
o(root.firstChild.nodeName).equals("DIV")
|
||||||
o(root.firstChild.attributes["id"].nodeValue).equals("a")
|
o(root.firstChild.attributes["id"].nodeValue).equals("a")
|
||||||
|
|
@ -311,7 +311,7 @@ o.spec("component", function() {
|
||||||
})
|
})
|
||||||
o("calls oninit before view", function() {
|
o("calls oninit before view", function() {
|
||||||
var viewCalled = false
|
var viewCalled = false
|
||||||
|
|
||||||
render(root, {
|
render(root, {
|
||||||
tag: {
|
tag: {
|
||||||
view: function() {
|
view: function() {
|
||||||
|
|
@ -332,14 +332,14 @@ o.spec("component", function() {
|
||||||
},
|
},
|
||||||
oninit: init,
|
oninit: init,
|
||||||
}
|
}
|
||||||
|
|
||||||
function view() {
|
function view() {
|
||||||
return {tag: component}
|
return {tag: component}
|
||||||
}
|
}
|
||||||
|
|
||||||
render(root, view())
|
render(root, view())
|
||||||
render(root, view())
|
render(root, view())
|
||||||
|
|
||||||
o(init.callCount).equals(1)
|
o(init.callCount).equals(1)
|
||||||
})
|
})
|
||||||
o("calls oncreate", function() {
|
o("calls oncreate", function() {
|
||||||
|
|
@ -347,7 +347,7 @@ o.spec("component", function() {
|
||||||
var component = {
|
var component = {
|
||||||
oncreate: function(vnode) {
|
oncreate: function(vnode) {
|
||||||
called++
|
called++
|
||||||
|
|
||||||
o(vnode.dom).notEquals(undefined)
|
o(vnode.dom).notEquals(undefined)
|
||||||
o(vnode.dom).equals(root.firstChild)
|
o(vnode.dom).equals(root.firstChild)
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
|
|
@ -357,9 +357,9 @@ o.spec("component", function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var node = {tag: component}
|
var node = {tag: component}
|
||||||
|
|
||||||
render(root, [node])
|
render(root, [node])
|
||||||
|
|
||||||
o(called).equals(1)
|
o(called).equals(1)
|
||||||
o(root.firstChild.nodeName).equals("DIV")
|
o(root.firstChild.nodeName).equals("DIV")
|
||||||
o(root.firstChild.attributes["id"].nodeValue).equals("a")
|
o(root.firstChild.attributes["id"].nodeValue).equals("a")
|
||||||
|
|
@ -373,14 +373,14 @@ o.spec("component", function() {
|
||||||
},
|
},
|
||||||
oncreate: create,
|
oncreate: create,
|
||||||
}
|
}
|
||||||
|
|
||||||
function view() {
|
function view() {
|
||||||
return {tag: component}
|
return {tag: component}
|
||||||
}
|
}
|
||||||
|
|
||||||
render(root, view())
|
render(root, view())
|
||||||
render(root, view())
|
render(root, view())
|
||||||
|
|
||||||
o(create.callCount).equals(1)
|
o(create.callCount).equals(1)
|
||||||
})
|
})
|
||||||
o("calls oncreate when returning fragment", function() {
|
o("calls oncreate when returning fragment", function() {
|
||||||
|
|
@ -388,7 +388,7 @@ o.spec("component", function() {
|
||||||
var component = {
|
var component = {
|
||||||
oncreate: function(vnode) {
|
oncreate: function(vnode) {
|
||||||
called++
|
called++
|
||||||
|
|
||||||
o(vnode.dom).notEquals(undefined)
|
o(vnode.dom).notEquals(undefined)
|
||||||
o(vnode.dom).equals(root.firstChild)
|
o(vnode.dom).equals(root.firstChild)
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
|
|
@ -398,9 +398,9 @@ o.spec("component", function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var node = {tag: component}
|
var node = {tag: component}
|
||||||
|
|
||||||
render(root, [node])
|
render(root, [node])
|
||||||
|
|
||||||
o(called).equals(1)
|
o(called).equals(1)
|
||||||
o(root.firstChild.nodeName).equals("DIV")
|
o(root.firstChild.nodeName).equals("DIV")
|
||||||
o(root.firstChild.attributes["id"].nodeValue).equals("a")
|
o(root.firstChild.attributes["id"].nodeValue).equals("a")
|
||||||
|
|
@ -411,7 +411,7 @@ o.spec("component", function() {
|
||||||
var component = {
|
var component = {
|
||||||
onupdate: function(vnode) {
|
onupdate: function(vnode) {
|
||||||
called++
|
called++
|
||||||
|
|
||||||
o(vnode.dom).notEquals(undefined)
|
o(vnode.dom).notEquals(undefined)
|
||||||
o(vnode.dom).equals(root.firstChild)
|
o(vnode.dom).equals(root.firstChild)
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
|
|
@ -420,13 +420,13 @@ o.spec("component", function() {
|
||||||
return {tag: "div", attrs: {id: "a"}, text: "b"}
|
return {tag: "div", attrs: {id: "a"}, text: "b"}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render(root, [{tag: component}])
|
render(root, [{tag: component}])
|
||||||
|
|
||||||
o(called).equals(0)
|
o(called).equals(0)
|
||||||
|
|
||||||
render(root, [{tag: component}])
|
render(root, [{tag: component}])
|
||||||
|
|
||||||
o(called).equals(1)
|
o(called).equals(1)
|
||||||
o(root.firstChild.nodeName).equals("DIV")
|
o(root.firstChild.nodeName).equals("DIV")
|
||||||
o(root.firstChild.attributes["id"].nodeValue).equals("a")
|
o(root.firstChild.attributes["id"].nodeValue).equals("a")
|
||||||
|
|
@ -437,7 +437,7 @@ o.spec("component", function() {
|
||||||
var component = {
|
var component = {
|
||||||
onupdate: function(vnode) {
|
onupdate: function(vnode) {
|
||||||
called++
|
called++
|
||||||
|
|
||||||
o(vnode.dom).notEquals(undefined)
|
o(vnode.dom).notEquals(undefined)
|
||||||
o(vnode.dom).equals(root.firstChild)
|
o(vnode.dom).equals(root.firstChild)
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
|
|
@ -446,13 +446,13 @@ o.spec("component", function() {
|
||||||
return [{tag: "div", attrs: {id: "a"}, text: "b"}]
|
return [{tag: "div", attrs: {id: "a"}, text: "b"}]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render(root, [{tag: component}])
|
render(root, [{tag: component}])
|
||||||
|
|
||||||
o(called).equals(0)
|
o(called).equals(0)
|
||||||
|
|
||||||
render(root, [{tag: component}])
|
render(root, [{tag: component}])
|
||||||
|
|
||||||
o(called).equals(1)
|
o(called).equals(1)
|
||||||
o(root.firstChild.nodeName).equals("DIV")
|
o(root.firstChild.nodeName).equals("DIV")
|
||||||
o(root.firstChild.attributes["id"].nodeValue).equals("a")
|
o(root.firstChild.attributes["id"].nodeValue).equals("a")
|
||||||
|
|
@ -463,7 +463,7 @@ o.spec("component", function() {
|
||||||
var component = {
|
var component = {
|
||||||
onremove: function(vnode) {
|
onremove: function(vnode) {
|
||||||
called++
|
called++
|
||||||
|
|
||||||
o(vnode.dom).notEquals(undefined)
|
o(vnode.dom).notEquals(undefined)
|
||||||
o(vnode.dom).equals(root.firstChild)
|
o(vnode.dom).equals(root.firstChild)
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
|
|
@ -472,13 +472,13 @@ o.spec("component", function() {
|
||||||
return {tag: "div", attrs: {id: "a"}, text: "b"}
|
return {tag: "div", attrs: {id: "a"}, text: "b"}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render(root, [{tag: component}])
|
render(root, [{tag: component}])
|
||||||
|
|
||||||
o(called).equals(0)
|
o(called).equals(0)
|
||||||
|
|
||||||
render(root, [])
|
render(root, [])
|
||||||
|
|
||||||
o(called).equals(1)
|
o(called).equals(1)
|
||||||
o(root.childNodes.length).equals(0)
|
o(root.childNodes.length).equals(0)
|
||||||
})
|
})
|
||||||
|
|
@ -487,7 +487,7 @@ o.spec("component", function() {
|
||||||
var component = {
|
var component = {
|
||||||
onremove: function(vnode) {
|
onremove: function(vnode) {
|
||||||
called++
|
called++
|
||||||
|
|
||||||
o(vnode.dom).notEquals(undefined)
|
o(vnode.dom).notEquals(undefined)
|
||||||
o(vnode.dom).equals(root.firstChild)
|
o(vnode.dom).equals(root.firstChild)
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
|
|
@ -496,13 +496,13 @@ o.spec("component", function() {
|
||||||
return [{tag: "div", attrs: {id: "a"}, text: "b"}]
|
return [{tag: "div", attrs: {id: "a"}, text: "b"}]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render(root, [{tag: component}])
|
render(root, [{tag: component}])
|
||||||
|
|
||||||
o(called).equals(0)
|
o(called).equals(0)
|
||||||
|
|
||||||
render(root, [])
|
render(root, [])
|
||||||
|
|
||||||
o(called).equals(1)
|
o(called).equals(1)
|
||||||
o(root.childNodes.length).equals(0)
|
o(root.childNodes.length).equals(0)
|
||||||
})
|
})
|
||||||
|
|
@ -511,24 +511,24 @@ o.spec("component", function() {
|
||||||
var component = {
|
var component = {
|
||||||
onbeforeremove: function(vnode, done) {
|
onbeforeremove: function(vnode, done) {
|
||||||
called++
|
called++
|
||||||
|
|
||||||
o(vnode.dom).notEquals(undefined)
|
o(vnode.dom).notEquals(undefined)
|
||||||
o(vnode.dom).equals(root.firstChild)
|
o(vnode.dom).equals(root.firstChild)
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
|
|
||||||
done()
|
done()
|
||||||
},
|
},
|
||||||
view: function() {
|
view: function() {
|
||||||
return {tag: "div", attrs: {id: "a"}, text: "b"}
|
return {tag: "div", attrs: {id: "a"}, text: "b"}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render(root, [{tag: component}])
|
render(root, [{tag: component}])
|
||||||
|
|
||||||
o(called).equals(0)
|
o(called).equals(0)
|
||||||
|
|
||||||
render(root, [])
|
render(root, [])
|
||||||
|
|
||||||
o(called).equals(1)
|
o(called).equals(1)
|
||||||
o(root.childNodes.length).equals(0)
|
o(root.childNodes.length).equals(0)
|
||||||
})
|
})
|
||||||
|
|
@ -537,24 +537,24 @@ o.spec("component", function() {
|
||||||
var component = {
|
var component = {
|
||||||
onbeforeremove: function(vnode, done) {
|
onbeforeremove: function(vnode, done) {
|
||||||
called++
|
called++
|
||||||
|
|
||||||
o(vnode.dom).notEquals(undefined)
|
o(vnode.dom).notEquals(undefined)
|
||||||
o(vnode.dom).equals(root.firstChild)
|
o(vnode.dom).equals(root.firstChild)
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
|
|
||||||
done()
|
done()
|
||||||
},
|
},
|
||||||
view: function() {
|
view: function() {
|
||||||
return [{tag: "div", attrs: {id: "a"}, text: "b"}]
|
return [{tag: "div", attrs: {id: "a"}, text: "b"}]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render(root, [{tag: component}])
|
render(root, [{tag: component}])
|
||||||
|
|
||||||
o(called).equals(0)
|
o(called).equals(0)
|
||||||
|
|
||||||
render(root, [])
|
render(root, [])
|
||||||
|
|
||||||
o(called).equals(1)
|
o(called).equals(1)
|
||||||
o(root.childNodes.length).equals(0)
|
o(root.childNodes.length).equals(0)
|
||||||
})
|
})
|
||||||
|
|
@ -568,11 +568,11 @@ o.spec("component", function() {
|
||||||
var update = o.spy()
|
var update = o.spy()
|
||||||
var vnode = {tag: component, key: 1}
|
var vnode = {tag: component, key: 1}
|
||||||
var updated = {tag: component, key: 1}
|
var updated = {tag: component, key: 1}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [])
|
render(root, [])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(vnode.dom).notEquals(updated.dom)
|
o(vnode.dom).notEquals(updated.dom)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
@ -586,12 +586,12 @@ o.spec("component", function() {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render(root, [{tag: component}])
|
render(root, [{tag: component}])
|
||||||
|
|
||||||
function init(vnode) {
|
function init(vnode) {
|
||||||
o(vnode.state.data).deepEquals([{a: 1}])
|
o(vnode.state.data).deepEquals([{a: 1}])
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -15,13 +15,13 @@ o.spec("createElement", function() {
|
||||||
o("creates element", function() {
|
o("creates element", function() {
|
||||||
var vnode = {tag: "div"}
|
var vnode = {tag: "div"}
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(vnode.dom.nodeName).equals("DIV")
|
o(vnode.dom.nodeName).equals("DIV")
|
||||||
})
|
})
|
||||||
o("creates attr", function() {
|
o("creates attr", function() {
|
||||||
var vnode = {tag: "div", attrs: {id: "a", title: "b"}}
|
var vnode = {tag: "div", attrs: {id: "a", title: "b"}}
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(vnode.dom.nodeName).equals("DIV")
|
o(vnode.dom.nodeName).equals("DIV")
|
||||||
o(vnode.dom.attributes["id"].nodeValue).equals("a")
|
o(vnode.dom.attributes["id"].nodeValue).equals("a")
|
||||||
o(vnode.dom.attributes["title"].nodeValue).equals("b")
|
o(vnode.dom.attributes["title"].nodeValue).equals("b")
|
||||||
|
|
@ -29,14 +29,14 @@ o.spec("createElement", function() {
|
||||||
o("creates style", function() {
|
o("creates style", function() {
|
||||||
var vnode = {tag: "div", attrs: {style: {backgroundColor: "red"}}}
|
var vnode = {tag: "div", attrs: {style: {backgroundColor: "red"}}}
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(vnode.dom.nodeName).equals("DIV")
|
o(vnode.dom.nodeName).equals("DIV")
|
||||||
o(vnode.dom.style.backgroundColor).equals("red")
|
o(vnode.dom.style.backgroundColor).equals("red")
|
||||||
})
|
})
|
||||||
o("creates children", function() {
|
o("creates children", function() {
|
||||||
var vnode = {tag: "div", children: [{tag: "a"}, {tag: "b"}]}
|
var vnode = {tag: "div", children: [{tag: "a"}, {tag: "b"}]}
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(vnode.dom.nodeName).equals("DIV")
|
o(vnode.dom.nodeName).equals("DIV")
|
||||||
o(vnode.dom.childNodes.length).equals(2)
|
o(vnode.dom.childNodes.length).equals(2)
|
||||||
o(vnode.dom.childNodes[0].nodeName).equals("A")
|
o(vnode.dom.childNodes[0].nodeName).equals("A")
|
||||||
|
|
@ -45,7 +45,7 @@ o.spec("createElement", function() {
|
||||||
o("creates attrs and children", function() {
|
o("creates attrs and children", function() {
|
||||||
var vnode = {tag: "div", attrs: {id: "a", title: "b"}, children: [{tag: "a"}, {tag: "b"}]}
|
var vnode = {tag: "div", attrs: {id: "a", title: "b"}, children: [{tag: "a"}, {tag: "b"}]}
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(vnode.dom.nodeName).equals("DIV")
|
o(vnode.dom.nodeName).equals("DIV")
|
||||||
o(vnode.dom.attributes["id"].nodeValue).equals("a")
|
o(vnode.dom.attributes["id"].nodeValue).equals("a")
|
||||||
o(vnode.dom.attributes["title"].nodeValue).equals("b")
|
o(vnode.dom.attributes["title"].nodeValue).equals("b")
|
||||||
|
|
@ -56,7 +56,7 @@ o.spec("createElement", function() {
|
||||||
o("creates svg", function() {
|
o("creates svg", function() {
|
||||||
var vnode = {tag: "svg", ns: "http://www.w3.org/2000/svg", children: [{tag: "a", ns: "http://www.w3.org/2000/svg", attrs: {"xlink:href": "javascript:;"}}]}
|
var vnode = {tag: "svg", ns: "http://www.w3.org/2000/svg", children: [{tag: "a", ns: "http://www.w3.org/2000/svg", attrs: {"xlink:href": "javascript:;"}}]}
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(vnode.dom.nodeName).equals("svg")
|
o(vnode.dom.nodeName).equals("svg")
|
||||||
o(vnode.dom.namespaceURI).equals("http://www.w3.org/2000/svg")
|
o(vnode.dom.namespaceURI).equals("http://www.w3.org/2000/svg")
|
||||||
o(vnode.dom.firstChild.nodeName).equals("a")
|
o(vnode.dom.firstChild.nodeName).equals("a")
|
||||||
|
|
@ -67,13 +67,13 @@ o.spec("createElement", function() {
|
||||||
o("sets attributes correctly for svg", function() {
|
o("sets attributes correctly for svg", function() {
|
||||||
var vnode = {tag: "svg", ns: "http://www.w3.org/2000/svg", attrs: {viewBox: "0 0 100 100"}}
|
var vnode = {tag: "svg", ns: "http://www.w3.org/2000/svg", attrs: {viewBox: "0 0 100 100"}}
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(vnode.dom.attributes["viewBox"].nodeValue).equals("0 0 100 100")
|
o(vnode.dom.attributes["viewBox"].nodeValue).equals("0 0 100 100")
|
||||||
})
|
})
|
||||||
o("creates mathml", function() {
|
o("creates mathml", function() {
|
||||||
var vnode = {tag: "math", ns: "http://www.w3.org/1998/Math/MathML", children: [{tag: "mrow", ns: "http://www.w3.org/1998/Math/MathML"}]}
|
var vnode = {tag: "math", ns: "http://www.w3.org/1998/Math/MathML", children: [{tag: "mrow", ns: "http://www.w3.org/1998/Math/MathML"}]}
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(vnode.dom.nodeName).equals("math")
|
o(vnode.dom.nodeName).equals("math")
|
||||||
o(vnode.dom.namespaceURI).equals("http://www.w3.org/1998/Math/MathML")
|
o(vnode.dom.namespaceURI).equals("http://www.w3.org/1998/Math/MathML")
|
||||||
o(vnode.dom.firstChild.nodeName).equals("mrow")
|
o(vnode.dom.firstChild.nodeName).equals("mrow")
|
||||||
|
|
|
||||||
|
|
@ -15,27 +15,27 @@ o.spec("createFragment", function() {
|
||||||
o("creates fragment", function() {
|
o("creates fragment", function() {
|
||||||
var vnode = {tag: "[", children: [{tag: "a"}]}
|
var vnode = {tag: "[", children: [{tag: "a"}]}
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(vnode.dom.nodeName).equals("A")
|
o(vnode.dom.nodeName).equals("A")
|
||||||
})
|
})
|
||||||
o("handles empty fragment", function() {
|
o("handles empty fragment", function() {
|
||||||
var vnode = {tag: "[", children: []}
|
var vnode = {tag: "[", children: []}
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(vnode.dom).equals(null)
|
o(vnode.dom).equals(null)
|
||||||
o(vnode.domSize).equals(0)
|
o(vnode.domSize).equals(0)
|
||||||
})
|
})
|
||||||
o("handles childless fragment", function() {
|
o("handles childless fragment", function() {
|
||||||
var vnode = {tag: "["}
|
var vnode = {tag: "["}
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(vnode.dom).equals(null)
|
o(vnode.dom).equals(null)
|
||||||
o(vnode.domSize).equals(0)
|
o(vnode.domSize).equals(0)
|
||||||
})
|
})
|
||||||
o("handles multiple children", function() {
|
o("handles multiple children", function() {
|
||||||
var vnode = {tag: "[", children: [{tag: "a"}, {tag: "b"}]}
|
var vnode = {tag: "[", children: [{tag: "a"}, {tag: "b"}]}
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(vnode.domSize).equals(2)
|
o(vnode.domSize).equals(2)
|
||||||
o(vnode.dom.nodeName).equals("A")
|
o(vnode.dom.nodeName).equals("A")
|
||||||
o(vnode.dom.nextSibling.nodeName).equals("B")
|
o(vnode.dom.nextSibling.nodeName).equals("B")
|
||||||
|
|
@ -43,7 +43,7 @@ o.spec("createFragment", function() {
|
||||||
o("handles td", function() {
|
o("handles td", function() {
|
||||||
var vnode = {tag: "[", children: [{tag: "td"}]}
|
var vnode = {tag: "[", children: [{tag: "td"}]}
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(vnode.dom).notEquals(null)
|
o(vnode.dom).notEquals(null)
|
||||||
o(vnode.dom.nodeName).equals("TD")
|
o(vnode.dom.nodeName).equals("TD")
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -15,26 +15,26 @@ o.spec("createHTML", function() {
|
||||||
o("creates HTML", function() {
|
o("creates HTML", function() {
|
||||||
var vnode = {tag: "<", children: "<a></a>"}
|
var vnode = {tag: "<", children: "<a></a>"}
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(vnode.dom.nodeName).equals("A")
|
o(vnode.dom.nodeName).equals("A")
|
||||||
})
|
})
|
||||||
o("creates text HTML", function() {
|
o("creates text HTML", function() {
|
||||||
var vnode = {tag: "<", children: "a"}
|
var vnode = {tag: "<", children: "a"}
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(vnode.dom.nodeValue).equals("a")
|
o(vnode.dom.nodeValue).equals("a")
|
||||||
})
|
})
|
||||||
o("handles empty HTML", function() {
|
o("handles empty HTML", function() {
|
||||||
var vnode = {tag: "<", children: ""}
|
var vnode = {tag: "<", children: ""}
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(vnode.dom).equals(null)
|
o(vnode.dom).equals(null)
|
||||||
o(vnode.domSize).equals(0)
|
o(vnode.domSize).equals(0)
|
||||||
})
|
})
|
||||||
o("handles multiple children", function() {
|
o("handles multiple children", function() {
|
||||||
var vnode = {tag: "<", children: "<a></a><b></b>"}
|
var vnode = {tag: "<", children: "<a></a><b></b>"}
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(vnode.domSize).equals(2)
|
o(vnode.domSize).equals(2)
|
||||||
o(vnode.dom.nodeName).equals("A")
|
o(vnode.dom.nodeName).equals("A")
|
||||||
o(vnode.dom.nextSibling.nodeName).equals("B")
|
o(vnode.dom.nextSibling.nodeName).equals("B")
|
||||||
|
|
@ -43,11 +43,11 @@ o.spec("createHTML", function() {
|
||||||
//FIXME body,head,html,frame,frameset are not supported
|
//FIXME body,head,html,frame,frameset are not supported
|
||||||
//FIXME keygen is broken in Firefox
|
//FIXME keygen is broken in Firefox
|
||||||
var tags = ["a", "abbr", "acronym", "address", "applet", "area", "article", "aside", "audio", "b", "base", "basefont", "bdi", "bdo", "big", "blockquote", /*"body",*/ "br", "button", "canvas", "caption", "center", "cite", "code", "col", "colgroup", "datalist", "dd", "del", "details", "dfn", "dialog", "dir", "div", "dl", "dt", "em", "embed", "fieldset", "figcaption", "figure", "font", "footer", "form", /*"frame", "frameset",*/ "h1", "h2", "h3", "h4", "h5", "h6", /*"head",*/ "header", "hr", /*"html",*/ "i", "iframe", "img", "input", "ins", "kbd", /*"keygen", */"label", "legend", "li", "link", "main", "map", "mark", "menu", "menuitem", "meta", "meter", "nav", "noframes", "noscript", "object", "ol", "optgroup", "option", "output", "p", "param", "pre", "progress", "q", "rp", "rt", "ruby", "s", "samp", "script", "section", "select", "small", "source", "span", "strike", "strong", "style", "sub", "summary", "sup", "table", "tbody", "td", "textarea", "tfoot", "th", "thead", "time", "title", "tr", "track", "tt", "u", "ul", "var", "video", "wbr"]
|
var tags = ["a", "abbr", "acronym", "address", "applet", "area", "article", "aside", "audio", "b", "base", "basefont", "bdi", "bdo", "big", "blockquote", /*"body",*/ "br", "button", "canvas", "caption", "center", "cite", "code", "col", "colgroup", "datalist", "dd", "del", "details", "dfn", "dialog", "dir", "div", "dl", "dt", "em", "embed", "fieldset", "figcaption", "figure", "font", "footer", "form", /*"frame", "frameset",*/ "h1", "h2", "h3", "h4", "h5", "h6", /*"head",*/ "header", "hr", /*"html",*/ "i", "iframe", "img", "input", "ins", "kbd", /*"keygen", */"label", "legend", "li", "link", "main", "map", "mark", "menu", "menuitem", "meta", "meter", "nav", "noframes", "noscript", "object", "ol", "optgroup", "option", "output", "p", "param", "pre", "progress", "q", "rp", "rt", "ruby", "s", "samp", "script", "section", "select", "small", "source", "span", "strike", "strong", "style", "sub", "summary", "sup", "table", "tbody", "td", "textarea", "tfoot", "th", "thead", "time", "title", "tr", "track", "tt", "u", "ul", "var", "video", "wbr"]
|
||||||
|
|
||||||
tags.forEach(function(tag) {
|
tags.forEach(function(tag) {
|
||||||
var vnode = {tag: "<", children: "<" + tag + " />"}
|
var vnode = {tag: "<", children: "<" + tag + " />"}
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(vnode.dom.nodeName).equals(tag.toUpperCase())
|
o(vnode.dom.nodeName).equals(tag.toUpperCase())
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ o.spec("createNodes", function() {
|
||||||
{tag: "[", children: [{tag: "#", children: "d"}]},
|
{tag: "[", children: [{tag: "#", children: "d"}]},
|
||||||
]
|
]
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(4)
|
o(root.childNodes.length).equals(4)
|
||||||
o(root.childNodes[0].nodeName).equals("A")
|
o(root.childNodes[0].nodeName).equals("A")
|
||||||
o(root.childNodes[1].nodeValue).equals("b")
|
o(root.childNodes[1].nodeValue).equals("b")
|
||||||
|
|
@ -36,7 +36,7 @@ o.spec("createNodes", function() {
|
||||||
{tag: "[", children: [{tag: "#", children: "d"}]},
|
{tag: "[", children: [{tag: "#", children: "d"}]},
|
||||||
]
|
]
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(4)
|
o(root.childNodes.length).equals(4)
|
||||||
o(root.childNodes[0].nodeName).equals("A")
|
o(root.childNodes[0].nodeName).equals("A")
|
||||||
o(root.childNodes[1].nodeValue).equals("b")
|
o(root.childNodes[1].nodeValue).equals("b")
|
||||||
|
|
@ -52,7 +52,7 @@ o.spec("createNodes", function() {
|
||||||
{tag: "[", children: [{tag: "#", children: "d"}]},
|
{tag: "[", children: [{tag: "#", children: "d"}]},
|
||||||
]
|
]
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(4)
|
o(root.childNodes.length).equals(4)
|
||||||
o(root.childNodes[0].nodeName).equals("A")
|
o(root.childNodes[0].nodeName).equals("A")
|
||||||
o(root.childNodes[1].nodeValue).equals("b")
|
o(root.childNodes[1].nodeValue).equals("b")
|
||||||
|
|
|
||||||
|
|
@ -15,56 +15,56 @@ o.spec("createText", function() {
|
||||||
o("creates string", function() {
|
o("creates string", function() {
|
||||||
var vnode = {tag: "#", children: "a"}
|
var vnode = {tag: "#", children: "a"}
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(vnode.dom.nodeName).equals("#text")
|
o(vnode.dom.nodeName).equals("#text")
|
||||||
o(vnode.dom.nodeValue).equals("a")
|
o(vnode.dom.nodeValue).equals("a")
|
||||||
})
|
})
|
||||||
o("creates falsy string", function() {
|
o("creates falsy string", function() {
|
||||||
var vnode = {tag: "#", children: ""}
|
var vnode = {tag: "#", children: ""}
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(vnode.dom.nodeName).equals("#text")
|
o(vnode.dom.nodeName).equals("#text")
|
||||||
o(vnode.dom.nodeValue).equals("")
|
o(vnode.dom.nodeValue).equals("")
|
||||||
})
|
})
|
||||||
o("creates number", function() {
|
o("creates number", function() {
|
||||||
var vnode = {tag: "#", children: 1}
|
var vnode = {tag: "#", children: 1}
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(vnode.dom.nodeName).equals("#text")
|
o(vnode.dom.nodeName).equals("#text")
|
||||||
o(vnode.dom.nodeValue).equals("1")
|
o(vnode.dom.nodeValue).equals("1")
|
||||||
})
|
})
|
||||||
o("creates falsy number", function() {
|
o("creates falsy number", function() {
|
||||||
var vnode = {tag: "#", children: 0}
|
var vnode = {tag: "#", children: 0}
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(vnode.dom.nodeName).equals("#text")
|
o(vnode.dom.nodeName).equals("#text")
|
||||||
o(vnode.dom.nodeValue).equals("0")
|
o(vnode.dom.nodeValue).equals("0")
|
||||||
})
|
})
|
||||||
o("creates boolean", function() {
|
o("creates boolean", function() {
|
||||||
var vnode = {tag: "#", children: true}
|
var vnode = {tag: "#", children: true}
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(vnode.dom.nodeName).equals("#text")
|
o(vnode.dom.nodeName).equals("#text")
|
||||||
o(vnode.dom.nodeValue).equals("true")
|
o(vnode.dom.nodeValue).equals("true")
|
||||||
})
|
})
|
||||||
o("creates falsy boolean", function() {
|
o("creates falsy boolean", function() {
|
||||||
var vnode = {tag: "#", children: false}
|
var vnode = {tag: "#", children: false}
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(vnode.dom.nodeName).equals("#text")
|
o(vnode.dom.nodeName).equals("#text")
|
||||||
o(vnode.dom.nodeValue).equals("false")
|
o(vnode.dom.nodeValue).equals("false")
|
||||||
})
|
})
|
||||||
o("creates spaces", function() {
|
o("creates spaces", function() {
|
||||||
var vnode = {tag: "#", children: " "}
|
var vnode = {tag: "#", children: " "}
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(vnode.dom.nodeName).equals("#text")
|
o(vnode.dom.nodeName).equals("#text")
|
||||||
o(vnode.dom.nodeValue).equals(" ")
|
o(vnode.dom.nodeValue).equals(" ")
|
||||||
})
|
})
|
||||||
o("ignores html", function() {
|
o("ignores html", function() {
|
||||||
var vnode = {tag: "#", children: "<a></a>™"}
|
var vnode = {tag: "#", children: "<a></a>™"}
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(vnode.dom.nodeName).equals("#text")
|
o(vnode.dom.nodeName).equals("#text")
|
||||||
o(vnode.dom.nodeValue).equals("<a></a>™")
|
o(vnode.dom.nodeValue).equals("<a></a>™")
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,10 @@ o.spec("event", function() {
|
||||||
var div = {tag: "div", attrs: {onclick: spy}}
|
var div = {tag: "div", attrs: {onclick: spy}}
|
||||||
var e = $window.document.createEvent("MouseEvents")
|
var e = $window.document.createEvent("MouseEvents")
|
||||||
e.initEvent("click", true, true)
|
e.initEvent("click", true, true)
|
||||||
|
|
||||||
render(root, [div])
|
render(root, [div])
|
||||||
div.dom.dispatchEvent(e)
|
div.dom.dispatchEvent(e)
|
||||||
|
|
||||||
o(spy.callCount).equals(1)
|
o(spy.callCount).equals(1)
|
||||||
o(spy.this).equals(div.dom)
|
o(spy.this).equals(div.dom)
|
||||||
o(spy.args[0].type).equals("click")
|
o(spy.args[0].type).equals("click")
|
||||||
|
|
@ -40,11 +40,11 @@ o.spec("event", function() {
|
||||||
var updated = {tag: "div", attrs: {id: "b", onclick: spy}}
|
var updated = {tag: "div", attrs: {id: "b", onclick: spy}}
|
||||||
var e = $window.document.createEvent("MouseEvents")
|
var e = $window.document.createEvent("MouseEvents")
|
||||||
e.initEvent("click", true, true)
|
e.initEvent("click", true, true)
|
||||||
|
|
||||||
render(root, [div])
|
render(root, [div])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
div.dom.dispatchEvent(e)
|
div.dom.dispatchEvent(e)
|
||||||
|
|
||||||
o(spy.callCount).equals(1)
|
o(spy.callCount).equals(1)
|
||||||
o(spy.this).equals(div.dom)
|
o(spy.this).equals(div.dom)
|
||||||
o(spy.args[0].type).equals("click")
|
o(spy.args[0].type).equals("click")
|
||||||
|
|
@ -62,10 +62,10 @@ o.spec("event", function() {
|
||||||
var div = {tag: "div", attrs: {ontransitionend: spy}}
|
var div = {tag: "div", attrs: {ontransitionend: spy}}
|
||||||
var e = $window.document.createEvent("HTMLEvents")
|
var e = $window.document.createEvent("HTMLEvents")
|
||||||
e.initEvent("transitionend", true, true)
|
e.initEvent("transitionend", true, true)
|
||||||
|
|
||||||
render(root, [div])
|
render(root, [div])
|
||||||
div.dom.dispatchEvent(e)
|
div.dom.dispatchEvent(e)
|
||||||
|
|
||||||
o(spy.callCount).equals(1)
|
o(spy.callCount).equals(1)
|
||||||
o(spy.this).equals(div.dom)
|
o(spy.this).equals(div.dom)
|
||||||
o(spy.args[0].type).equals("transitionend")
|
o(spy.args[0].type).equals("transitionend")
|
||||||
|
|
@ -75,4 +75,4 @@ o.spec("event", function() {
|
||||||
o(onevent.args[0].type).equals("transitionend")
|
o(onevent.args[0].type).equals("transitionend")
|
||||||
o(onevent.args[0].target).equals(div.dom)
|
o(onevent.args[0].target).equals(div.dom)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -5,55 +5,55 @@ o.spec("hyperscript", function() {
|
||||||
o.spec("selector", function() {
|
o.spec("selector", function() {
|
||||||
o("handles tag in selector", function() {
|
o("handles tag in selector", function() {
|
||||||
var vnode = m("a")
|
var vnode = m("a")
|
||||||
|
|
||||||
o(vnode.tag).equals("a")
|
o(vnode.tag).equals("a")
|
||||||
})
|
})
|
||||||
o("handles class in selector", function() {
|
o("handles class in selector", function() {
|
||||||
var vnode = m(".a")
|
var vnode = m(".a")
|
||||||
|
|
||||||
o(vnode.tag).equals("div")
|
o(vnode.tag).equals("div")
|
||||||
o(vnode.attrs.className).equals("a")
|
o(vnode.attrs.className).equals("a")
|
||||||
})
|
})
|
||||||
o("handles many classes in selector", function() {
|
o("handles many classes in selector", function() {
|
||||||
var vnode = m(".a.b.c")
|
var vnode = m(".a.b.c")
|
||||||
|
|
||||||
o(vnode.tag).equals("div")
|
o(vnode.tag).equals("div")
|
||||||
o(vnode.attrs.className).equals("a b c")
|
o(vnode.attrs.className).equals("a b c")
|
||||||
})
|
})
|
||||||
o("handles id in selector", function() {
|
o("handles id in selector", function() {
|
||||||
var vnode = m("#a")
|
var vnode = m("#a")
|
||||||
|
|
||||||
o(vnode.tag).equals("div")
|
o(vnode.tag).equals("div")
|
||||||
o(vnode.attrs.id).equals("a")
|
o(vnode.attrs.id).equals("a")
|
||||||
})
|
})
|
||||||
o("handles attr in selector", function() {
|
o("handles attr in selector", function() {
|
||||||
var vnode = m("[a=b]")
|
var vnode = m("[a=b]")
|
||||||
|
|
||||||
o(vnode.tag).equals("div")
|
o(vnode.tag).equals("div")
|
||||||
o(vnode.attrs.a).equals("b")
|
o(vnode.attrs.a).equals("b")
|
||||||
})
|
})
|
||||||
o("handles many attrs in selector", function() {
|
o("handles many attrs in selector", function() {
|
||||||
var vnode = m("[a=b][c=d]")
|
var vnode = m("[a=b][c=d]")
|
||||||
|
|
||||||
o(vnode.tag).equals("div")
|
o(vnode.tag).equals("div")
|
||||||
o(vnode.attrs.a).equals("b")
|
o(vnode.attrs.a).equals("b")
|
||||||
o(vnode.attrs.c).equals("d")
|
o(vnode.attrs.c).equals("d")
|
||||||
})
|
})
|
||||||
o("handles attr w/ spaces in selector", function() {
|
o("handles attr w/ spaces in selector", function() {
|
||||||
var vnode = m("[a = b]")
|
var vnode = m("[a = b]")
|
||||||
|
|
||||||
o(vnode.tag).equals("div")
|
o(vnode.tag).equals("div")
|
||||||
o(vnode.attrs.a).equals("b")
|
o(vnode.attrs.a).equals("b")
|
||||||
})
|
})
|
||||||
o("handles attr w/ quotes in selector", function() {
|
o("handles attr w/ quotes in selector", function() {
|
||||||
var vnode = m("[a='b']")
|
var vnode = m("[a='b']")
|
||||||
|
|
||||||
o(vnode.tag).equals("div")
|
o(vnode.tag).equals("div")
|
||||||
o(vnode.attrs.a).equals("b")
|
o(vnode.attrs.a).equals("b")
|
||||||
})
|
})
|
||||||
o("handles attr w/ quoted square bracket", function() {
|
o("handles attr w/ quoted square bracket", function() {
|
||||||
var vnode = m("[x][a='[b]'].c")
|
var vnode = m("[x][a='[b]'].c")
|
||||||
|
|
||||||
o(vnode.tag).equals("div")
|
o(vnode.tag).equals("div")
|
||||||
o(vnode.attrs.x).equals(true)
|
o(vnode.attrs.x).equals(true)
|
||||||
o(vnode.attrs.a).equals("[b]")
|
o(vnode.attrs.a).equals("[b]")
|
||||||
|
|
@ -61,55 +61,55 @@ o.spec("hyperscript", function() {
|
||||||
})
|
})
|
||||||
o("handles attr w/ unmatched square bracket", function() {
|
o("handles attr w/ unmatched square bracket", function() {
|
||||||
var vnode = m("[a=']'].c")
|
var vnode = m("[a=']'].c")
|
||||||
|
|
||||||
o(vnode.tag).equals("div")
|
o(vnode.tag).equals("div")
|
||||||
o(vnode.attrs.a).equals("]")
|
o(vnode.attrs.a).equals("]")
|
||||||
o(vnode.attrs.className).equals("c")
|
o(vnode.attrs.className).equals("c")
|
||||||
})
|
})
|
||||||
o("handles attr w/ quoted square bracket and quote", function() {
|
o("handles attr w/ quoted square bracket and quote", function() {
|
||||||
var vnode = m("[a='[b\"\\']'].c") // `[a='[b"\']']`
|
var vnode = m("[a='[b\"\\']'].c") // `[a='[b"\']']`
|
||||||
|
|
||||||
o(vnode.tag).equals("div")
|
o(vnode.tag).equals("div")
|
||||||
o(vnode.attrs.a).equals("[b\"']") // `[b"']`
|
o(vnode.attrs.a).equals("[b\"']") // `[b"']`
|
||||||
o(vnode.attrs.className).equals("c")
|
o(vnode.attrs.className).equals("c")
|
||||||
})
|
})
|
||||||
o("handles attr w/ quoted square containing escaped square bracket", function() {
|
o("handles attr w/ quoted square containing escaped square bracket", function() {
|
||||||
var vnode = m("[a='[\\]]'].c") // `[a='[\]]']`
|
var vnode = m("[a='[\\]]'].c") // `[a='[\]]']`
|
||||||
|
|
||||||
o(vnode.tag).equals("div")
|
o(vnode.tag).equals("div")
|
||||||
o(vnode.attrs.a).equals("[\\]]") // `[\]]`
|
o(vnode.attrs.a).equals("[\\]]") // `[\]]`
|
||||||
o(vnode.attrs.className).equals("c")
|
o(vnode.attrs.className).equals("c")
|
||||||
})
|
})
|
||||||
o("handles attr w/ backslashes", function() {
|
o("handles attr w/ backslashes", function() {
|
||||||
var vnode = m("[a='\\\\'].c") // `[a='\\']`
|
var vnode = m("[a='\\\\'].c") // `[a='\\']`
|
||||||
|
|
||||||
o(vnode.tag).equals("div")
|
o(vnode.tag).equals("div")
|
||||||
o(vnode.attrs.a).equals("\\")
|
o(vnode.attrs.a).equals("\\")
|
||||||
o(vnode.attrs.className).equals("c")
|
o(vnode.attrs.className).equals("c")
|
||||||
})
|
})
|
||||||
o("handles attr w/ quotes and spaces in selector", function() {
|
o("handles attr w/ quotes and spaces in selector", function() {
|
||||||
var vnode = m("[a = 'b']")
|
var vnode = m("[a = 'b']")
|
||||||
|
|
||||||
o(vnode.tag).equals("div")
|
o(vnode.tag).equals("div")
|
||||||
o(vnode.attrs.a).equals("b")
|
o(vnode.attrs.a).equals("b")
|
||||||
})
|
})
|
||||||
o("handles many attr w/ quotes and spaces in selector", function() {
|
o("handles many attr w/ quotes and spaces in selector", function() {
|
||||||
var vnode = m("[a = 'b'][c = 'd']")
|
var vnode = m("[a = 'b'][c = 'd']")
|
||||||
|
|
||||||
o(vnode.tag).equals("div")
|
o(vnode.tag).equals("div")
|
||||||
o(vnode.attrs.a).equals("b")
|
o(vnode.attrs.a).equals("b")
|
||||||
o(vnode.attrs.c).equals("d")
|
o(vnode.attrs.c).equals("d")
|
||||||
})
|
})
|
||||||
o("handles tag, class, attrs in selector", function() {
|
o("handles tag, class, attrs in selector", function() {
|
||||||
var vnode = m("a.b[c = 'd']")
|
var vnode = m("a.b[c = 'd']")
|
||||||
|
|
||||||
o(vnode.tag).equals("a")
|
o(vnode.tag).equals("a")
|
||||||
o(vnode.attrs.className).equals("b")
|
o(vnode.attrs.className).equals("b")
|
||||||
o(vnode.attrs.c).equals("d")
|
o(vnode.attrs.c).equals("d")
|
||||||
})
|
})
|
||||||
o("handles tag, mixed classes, attrs in selector", function() {
|
o("handles tag, mixed classes, attrs in selector", function() {
|
||||||
var vnode = m("a.b[c = 'd'].e[f = 'g']")
|
var vnode = m("a.b[c = 'd'].e[f = 'g']")
|
||||||
|
|
||||||
o(vnode.tag).equals("a")
|
o(vnode.tag).equals("a")
|
||||||
o(vnode.attrs.className).equals("b e")
|
o(vnode.attrs.className).equals("b e")
|
||||||
o(vnode.attrs.c).equals("d")
|
o(vnode.attrs.c).equals("d")
|
||||||
|
|
@ -117,7 +117,7 @@ o.spec("hyperscript", function() {
|
||||||
})
|
})
|
||||||
o("handles attr without value", function() {
|
o("handles attr without value", function() {
|
||||||
var vnode = m("[a]")
|
var vnode = m("[a]")
|
||||||
|
|
||||||
o(vnode.tag).equals("div")
|
o(vnode.tag).equals("div")
|
||||||
o(vnode.attrs.a).equals(true)
|
o(vnode.attrs.a).equals(true)
|
||||||
})
|
})
|
||||||
|
|
@ -125,102 +125,102 @@ o.spec("hyperscript", function() {
|
||||||
o.spec("attrs", function() {
|
o.spec("attrs", function() {
|
||||||
o("handles string attr", function() {
|
o("handles string attr", function() {
|
||||||
var vnode = m("div", {a: "b"})
|
var vnode = m("div", {a: "b"})
|
||||||
|
|
||||||
o(vnode.tag).equals("div")
|
o(vnode.tag).equals("div")
|
||||||
o(vnode.attrs.a).equals("b")
|
o(vnode.attrs.a).equals("b")
|
||||||
})
|
})
|
||||||
o("handles falsy string attr", function() {
|
o("handles falsy string attr", function() {
|
||||||
var vnode = m("div", {a: ""})
|
var vnode = m("div", {a: ""})
|
||||||
|
|
||||||
o(vnode.tag).equals("div")
|
o(vnode.tag).equals("div")
|
||||||
o(vnode.attrs.a).equals("")
|
o(vnode.attrs.a).equals("")
|
||||||
})
|
})
|
||||||
o("handles number attr", function() {
|
o("handles number attr", function() {
|
||||||
var vnode = m("div", {a: 1})
|
var vnode = m("div", {a: 1})
|
||||||
|
|
||||||
o(vnode.tag).equals("div")
|
o(vnode.tag).equals("div")
|
||||||
o(vnode.attrs.a).equals(1)
|
o(vnode.attrs.a).equals(1)
|
||||||
})
|
})
|
||||||
o("handles falsy number attr", function() {
|
o("handles falsy number attr", function() {
|
||||||
var vnode = m("div", {a: 0})
|
var vnode = m("div", {a: 0})
|
||||||
|
|
||||||
o(vnode.tag).equals("div")
|
o(vnode.tag).equals("div")
|
||||||
o(vnode.attrs.a).equals(0)
|
o(vnode.attrs.a).equals(0)
|
||||||
})
|
})
|
||||||
o("handles boolean attr", function() {
|
o("handles boolean attr", function() {
|
||||||
var vnode = m("div", {a: true})
|
var vnode = m("div", {a: true})
|
||||||
|
|
||||||
o(vnode.tag).equals("div")
|
o(vnode.tag).equals("div")
|
||||||
o(vnode.attrs.a).equals(true)
|
o(vnode.attrs.a).equals(true)
|
||||||
})
|
})
|
||||||
o("handles falsy boolean attr", function() {
|
o("handles falsy boolean attr", function() {
|
||||||
var vnode = m("div", {a: false})
|
var vnode = m("div", {a: false})
|
||||||
|
|
||||||
o(vnode.tag).equals("div")
|
o(vnode.tag).equals("div")
|
||||||
o(vnode.attrs.a).equals(false)
|
o(vnode.attrs.a).equals(false)
|
||||||
})
|
})
|
||||||
o("handles many attrs", function() {
|
o("handles many attrs", function() {
|
||||||
var vnode = m("div", {a: "b", c: "d"})
|
var vnode = m("div", {a: "b", c: "d"})
|
||||||
|
|
||||||
o(vnode.tag).equals("div")
|
o(vnode.tag).equals("div")
|
||||||
o(vnode.attrs.a).equals("b")
|
o(vnode.attrs.a).equals("b")
|
||||||
o(vnode.attrs.c).equals("d")
|
o(vnode.attrs.c).equals("d")
|
||||||
})
|
})
|
||||||
o("handles merging classes w/ class property", function() {
|
o("handles merging classes w/ class property", function() {
|
||||||
var vnode = m(".a", {class: "b"})
|
var vnode = m(".a", {class: "b"})
|
||||||
|
|
||||||
o(vnode.attrs.className).equals("a b")
|
o(vnode.attrs.className).equals("a b")
|
||||||
})
|
})
|
||||||
o("handles merging classes w/ className property", function() {
|
o("handles merging classes w/ className property", function() {
|
||||||
var vnode = m(".a", {className: "b"})
|
var vnode = m(".a", {className: "b"})
|
||||||
|
|
||||||
o(vnode.attrs.className).equals("a b")
|
o(vnode.attrs.className).equals("a b")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
o.spec("children", function() {
|
o.spec("children", function() {
|
||||||
o("handles string single child", function() {
|
o("handles string single child", function() {
|
||||||
var vnode = m("div", {}, ["a"])
|
var vnode = m("div", {}, ["a"])
|
||||||
|
|
||||||
o(vnode.text).equals("a")
|
o(vnode.text).equals("a")
|
||||||
})
|
})
|
||||||
o("handles falsy string single child", function() {
|
o("handles falsy string single child", function() {
|
||||||
var vnode = m("div", {}, [""])
|
var vnode = m("div", {}, [""])
|
||||||
|
|
||||||
o(vnode.text).equals("")
|
o(vnode.text).equals("")
|
||||||
})
|
})
|
||||||
o("handles number single child", function() {
|
o("handles number single child", function() {
|
||||||
var vnode = m("div", {}, [1])
|
var vnode = m("div", {}, [1])
|
||||||
|
|
||||||
o(vnode.text).equals(1)
|
o(vnode.text).equals(1)
|
||||||
})
|
})
|
||||||
o("handles falsy number single child", function() {
|
o("handles falsy number single child", function() {
|
||||||
var vnode = m("div", {}, [0])
|
var vnode = m("div", {}, [0])
|
||||||
|
|
||||||
o(vnode.text).equals(0)
|
o(vnode.text).equals(0)
|
||||||
})
|
})
|
||||||
o("handles boolean single child", function() {
|
o("handles boolean single child", function() {
|
||||||
var vnode = m("div", {}, [true])
|
var vnode = m("div", {}, [true])
|
||||||
|
|
||||||
o(vnode.text).equals(true)
|
o(vnode.text).equals(true)
|
||||||
})
|
})
|
||||||
o("handles falsy boolean single child", function() {
|
o("handles falsy boolean single child", function() {
|
||||||
var vnode = m("div", {}, [false])
|
var vnode = m("div", {}, [false])
|
||||||
|
|
||||||
o(vnode.text).equals(false)
|
o(vnode.text).equals(false)
|
||||||
})
|
})
|
||||||
o("handles null single child", function() {
|
o("handles null single child", function() {
|
||||||
var vnode = m("div", {}, [null])
|
var vnode = m("div", {}, [null])
|
||||||
|
|
||||||
o(vnode.children[0]).equals(null)
|
o(vnode.children[0]).equals(null)
|
||||||
})
|
})
|
||||||
o("handles undefined single child", function() {
|
o("handles undefined single child", function() {
|
||||||
var vnode = m("div", {}, [undefined])
|
var vnode = m("div", {}, [undefined])
|
||||||
|
|
||||||
o(vnode.children[0]).equals(undefined)
|
o(vnode.children[0]).equals(undefined)
|
||||||
})
|
})
|
||||||
o("handles multiple string children", function() {
|
o("handles multiple string children", function() {
|
||||||
var vnode = m("div", {}, ["", "a"])
|
var vnode = m("div", {}, ["", "a"])
|
||||||
|
|
||||||
o(vnode.children[0].tag).equals("#")
|
o(vnode.children[0].tag).equals("#")
|
||||||
o(vnode.children[0].children).equals("")
|
o(vnode.children[0].children).equals("")
|
||||||
o(vnode.children[1].tag).equals("#")
|
o(vnode.children[1].tag).equals("#")
|
||||||
|
|
@ -228,7 +228,7 @@ o.spec("hyperscript", function() {
|
||||||
})
|
})
|
||||||
o("handles multiple number children", function() {
|
o("handles multiple number children", function() {
|
||||||
var vnode = m("div", {}, [0, 1])
|
var vnode = m("div", {}, [0, 1])
|
||||||
|
|
||||||
o(vnode.children[0].tag).equals("#")
|
o(vnode.children[0].tag).equals("#")
|
||||||
o(vnode.children[0].children).equals(0)
|
o(vnode.children[0].children).equals(0)
|
||||||
o(vnode.children[1].tag).equals("#")
|
o(vnode.children[1].tag).equals("#")
|
||||||
|
|
@ -236,7 +236,7 @@ o.spec("hyperscript", function() {
|
||||||
})
|
})
|
||||||
o("handles multiple boolean children", function() {
|
o("handles multiple boolean children", function() {
|
||||||
var vnode = m("div", {}, [false, true])
|
var vnode = m("div", {}, [false, true])
|
||||||
|
|
||||||
o(vnode.children[0].tag).equals("#")
|
o(vnode.children[0].tag).equals("#")
|
||||||
o(vnode.children[0].children).equals(false)
|
o(vnode.children[0].children).equals(false)
|
||||||
o(vnode.children[1].tag).equals("#")
|
o(vnode.children[1].tag).equals("#")
|
||||||
|
|
@ -244,7 +244,7 @@ o.spec("hyperscript", function() {
|
||||||
})
|
})
|
||||||
o("handles multiple null/undefined child", function() {
|
o("handles multiple null/undefined child", function() {
|
||||||
var vnode = m("div", {}, [null, undefined])
|
var vnode = m("div", {}, [null, undefined])
|
||||||
|
|
||||||
o(vnode.children[0]).equals(null)
|
o(vnode.children[0]).equals(null)
|
||||||
o(vnode.children[1]).equals(undefined)
|
o(vnode.children[1]).equals(undefined)
|
||||||
})
|
})
|
||||||
|
|
@ -252,47 +252,47 @@ o.spec("hyperscript", function() {
|
||||||
o.spec("permutations", function() {
|
o.spec("permutations", function() {
|
||||||
o("handles null attr and children", function() {
|
o("handles null attr and children", function() {
|
||||||
var vnode = m("div", null, [m("a"), m("b")])
|
var vnode = m("div", null, [m("a"), m("b")])
|
||||||
|
|
||||||
o(vnode.children.length).equals(2)
|
o(vnode.children.length).equals(2)
|
||||||
o(vnode.children[0].tag).equals("a")
|
o(vnode.children[0].tag).equals("a")
|
||||||
o(vnode.children[1].tag).equals("b")
|
o(vnode.children[1].tag).equals("b")
|
||||||
})
|
})
|
||||||
o("handles null attr and child unwrapped", function() {
|
o("handles null attr and child unwrapped", function() {
|
||||||
var vnode = m("div", null, m("a"))
|
var vnode = m("div", null, m("a"))
|
||||||
|
|
||||||
o(vnode.children.length).equals(1)
|
o(vnode.children.length).equals(1)
|
||||||
o(vnode.children[0].tag).equals("a")
|
o(vnode.children[0].tag).equals("a")
|
||||||
})
|
})
|
||||||
o("handles null attr and children unwrapped", function() {
|
o("handles null attr and children unwrapped", function() {
|
||||||
var vnode = m("div", null, m("a"), m("b"))
|
var vnode = m("div", null, m("a"), m("b"))
|
||||||
|
|
||||||
o(vnode.children.length).equals(2)
|
o(vnode.children.length).equals(2)
|
||||||
o(vnode.children[0].tag).equals("a")
|
o(vnode.children[0].tag).equals("a")
|
||||||
o(vnode.children[1].tag).equals("b")
|
o(vnode.children[1].tag).equals("b")
|
||||||
})
|
})
|
||||||
o("handles attr and children", function() {
|
o("handles attr and children", function() {
|
||||||
var vnode = m("div", {a: "b"}, [m("i"), m("s")])
|
var vnode = m("div", {a: "b"}, [m("i"), m("s")])
|
||||||
|
|
||||||
o(vnode.attrs.a).equals("b")
|
o(vnode.attrs.a).equals("b")
|
||||||
o(vnode.children[0].tag).equals("i")
|
o(vnode.children[0].tag).equals("i")
|
||||||
o(vnode.children[1].tag).equals("s")
|
o(vnode.children[1].tag).equals("s")
|
||||||
})
|
})
|
||||||
o("handles attr and child unwrapped", function() {
|
o("handles attr and child unwrapped", function() {
|
||||||
var vnode = m("div", {a: "b"}, m("i"))
|
var vnode = m("div", {a: "b"}, m("i"))
|
||||||
|
|
||||||
o(vnode.attrs.a).equals("b")
|
o(vnode.attrs.a).equals("b")
|
||||||
o(vnode.children[0].tag).equals("i")
|
o(vnode.children[0].tag).equals("i")
|
||||||
})
|
})
|
||||||
o("handles attr and children unwrapped", function() {
|
o("handles attr and children unwrapped", function() {
|
||||||
var vnode = m("div", {a: "b"}, m("i"), m("s"))
|
var vnode = m("div", {a: "b"}, m("i"), m("s"))
|
||||||
|
|
||||||
o(vnode.attrs.a).equals("b")
|
o(vnode.attrs.a).equals("b")
|
||||||
o(vnode.children[0].tag).equals("i")
|
o(vnode.children[0].tag).equals("i")
|
||||||
o(vnode.children[1].tag).equals("s")
|
o(vnode.children[1].tag).equals("s")
|
||||||
})
|
})
|
||||||
o("handles attr and text children", function() {
|
o("handles attr and text children", function() {
|
||||||
var vnode = m("div", {a: "b"}, ["c", "d"])
|
var vnode = m("div", {a: "b"}, ["c", "d"])
|
||||||
|
|
||||||
o(vnode.attrs.a).equals("b")
|
o(vnode.attrs.a).equals("b")
|
||||||
o(vnode.children[0].tag).equals("#")
|
o(vnode.children[0].tag).equals("#")
|
||||||
o(vnode.children[0].children).equals("c")
|
o(vnode.children[0].children).equals("c")
|
||||||
|
|
@ -301,49 +301,49 @@ o.spec("hyperscript", function() {
|
||||||
})
|
})
|
||||||
o("handles attr and single string text child", function() {
|
o("handles attr and single string text child", function() {
|
||||||
var vnode = m("div", {a: "b"}, ["c"])
|
var vnode = m("div", {a: "b"}, ["c"])
|
||||||
|
|
||||||
o(vnode.attrs.a).equals("b")
|
o(vnode.attrs.a).equals("b")
|
||||||
o(vnode.text).equals("c")
|
o(vnode.text).equals("c")
|
||||||
})
|
})
|
||||||
o("handles attr and single falsy string text child", function() {
|
o("handles attr and single falsy string text child", function() {
|
||||||
var vnode = m("div", {a: "b"}, [""])
|
var vnode = m("div", {a: "b"}, [""])
|
||||||
|
|
||||||
o(vnode.attrs.a).equals("b")
|
o(vnode.attrs.a).equals("b")
|
||||||
o(vnode.text).equals("")
|
o(vnode.text).equals("")
|
||||||
})
|
})
|
||||||
o("handles attr and single number text child", function() {
|
o("handles attr and single number text child", function() {
|
||||||
var vnode = m("div", {a: "b"}, [1])
|
var vnode = m("div", {a: "b"}, [1])
|
||||||
|
|
||||||
o(vnode.attrs.a).equals("b")
|
o(vnode.attrs.a).equals("b")
|
||||||
o(vnode.text).equals(1)
|
o(vnode.text).equals(1)
|
||||||
})
|
})
|
||||||
o("handles attr and single falsy number text child", function() {
|
o("handles attr and single falsy number text child", function() {
|
||||||
var vnode = m("div", {a: "b"}, [0])
|
var vnode = m("div", {a: "b"}, [0])
|
||||||
|
|
||||||
o(vnode.attrs.a).equals("b")
|
o(vnode.attrs.a).equals("b")
|
||||||
o(vnode.text).equals(0)
|
o(vnode.text).equals(0)
|
||||||
})
|
})
|
||||||
o("handles attr and single boolean text child", function() {
|
o("handles attr and single boolean text child", function() {
|
||||||
var vnode = m("div", {a: "b"}, [true])
|
var vnode = m("div", {a: "b"}, [true])
|
||||||
|
|
||||||
o(vnode.attrs.a).equals("b")
|
o(vnode.attrs.a).equals("b")
|
||||||
o(vnode.text).equals(true)
|
o(vnode.text).equals(true)
|
||||||
})
|
})
|
||||||
o("handles attr and single falsy boolean text child", function() {
|
o("handles attr and single falsy boolean text child", function() {
|
||||||
var vnode = m("div", {a: "b"}, [false])
|
var vnode = m("div", {a: "b"}, [false])
|
||||||
|
|
||||||
o(vnode.attrs.a).equals("b")
|
o(vnode.attrs.a).equals("b")
|
||||||
o(vnode.text).equals(false)
|
o(vnode.text).equals(false)
|
||||||
})
|
})
|
||||||
o("handles attr and single text child unwrapped", function() {
|
o("handles attr and single text child unwrapped", function() {
|
||||||
var vnode = m("div", {a: "b"}, "c")
|
var vnode = m("div", {a: "b"}, "c")
|
||||||
|
|
||||||
o(vnode.attrs.a).equals("b")
|
o(vnode.attrs.a).equals("b")
|
||||||
o(vnode.text).equals("c")
|
o(vnode.text).equals("c")
|
||||||
})
|
})
|
||||||
o("handles attr and text children unwrapped", function() {
|
o("handles attr and text children unwrapped", function() {
|
||||||
var vnode = m("div", {a: "b"}, "c", "d")
|
var vnode = m("div", {a: "b"}, "c", "d")
|
||||||
|
|
||||||
o(vnode.attrs.a).equals("b")
|
o(vnode.attrs.a).equals("b")
|
||||||
o(vnode.children[0].tag).equals("#")
|
o(vnode.children[0].tag).equals("#")
|
||||||
o(vnode.children[0].children).equals("c")
|
o(vnode.children[0].children).equals("c")
|
||||||
|
|
@ -352,27 +352,27 @@ o.spec("hyperscript", function() {
|
||||||
})
|
})
|
||||||
o("handles children without attr", function() {
|
o("handles children without attr", function() {
|
||||||
var vnode = m("div", [m("i"), m("s")])
|
var vnode = m("div", [m("i"), m("s")])
|
||||||
|
|
||||||
o(vnode.attrs).equals(undefined)
|
o(vnode.attrs).equals(undefined)
|
||||||
o(vnode.children[0].tag).equals("i")
|
o(vnode.children[0].tag).equals("i")
|
||||||
o(vnode.children[1].tag).equals("s")
|
o(vnode.children[1].tag).equals("s")
|
||||||
})
|
})
|
||||||
o("handles child without attr unwrapped", function() {
|
o("handles child without attr unwrapped", function() {
|
||||||
var vnode = m("div", m("i"))
|
var vnode = m("div", m("i"))
|
||||||
|
|
||||||
o(vnode.attrs).equals(undefined)
|
o(vnode.attrs).equals(undefined)
|
||||||
o(vnode.children[0].tag).equals("i")
|
o(vnode.children[0].tag).equals("i")
|
||||||
})
|
})
|
||||||
o("handles children without attr unwrapped", function() {
|
o("handles children without attr unwrapped", function() {
|
||||||
var vnode = m("div", m("i"), m("s"))
|
var vnode = m("div", m("i"), m("s"))
|
||||||
|
|
||||||
o(vnode.attrs).equals(undefined)
|
o(vnode.attrs).equals(undefined)
|
||||||
o(vnode.children[0].tag).equals("i")
|
o(vnode.children[0].tag).equals("i")
|
||||||
o(vnode.children[1].tag).equals("s")
|
o(vnode.children[1].tag).equals("s")
|
||||||
})
|
})
|
||||||
o("handles fragment children without attr unwrapped", function() {
|
o("handles fragment children without attr unwrapped", function() {
|
||||||
var vnode = m("div", [m("i")], [m("s")])
|
var vnode = m("div", [m("i")], [m("s")])
|
||||||
|
|
||||||
o(vnode.children[0].tag).equals("[")
|
o(vnode.children[0].tag).equals("[")
|
||||||
o(vnode.children[0].children[0].tag).equals("i")
|
o(vnode.children[0].children[0].tag).equals("i")
|
||||||
o(vnode.children[1].tag).equals("[")
|
o(vnode.children[1].tag).equals("[")
|
||||||
|
|
@ -380,14 +380,14 @@ o.spec("hyperscript", function() {
|
||||||
})
|
})
|
||||||
o("handles children with nested array", function() {
|
o("handles children with nested array", function() {
|
||||||
var vnode = m("div", [[m("i"), m("s")]])
|
var vnode = m("div", [[m("i"), m("s")]])
|
||||||
|
|
||||||
o(vnode.children[0].tag).equals("[")
|
o(vnode.children[0].tag).equals("[")
|
||||||
o(vnode.children[0].children[0].tag).equals("i")
|
o(vnode.children[0].children[0].tag).equals("i")
|
||||||
o(vnode.children[0].children[1].tag).equals("s")
|
o(vnode.children[0].children[1].tag).equals("s")
|
||||||
})
|
})
|
||||||
o("handles children with deeply nested array", function() {
|
o("handles children with deeply nested array", function() {
|
||||||
var vnode = m("div", [[[m("i"), m("s")]]])
|
var vnode = m("div", [[[m("i"), m("s")]]])
|
||||||
|
|
||||||
o(vnode.children[0].tag).equals("[")
|
o(vnode.children[0].tag).equals("[")
|
||||||
o(vnode.children[0].children[0].tag).equals("[")
|
o(vnode.children[0].children[0].tag).equals("[")
|
||||||
o(vnode.children[0].children[0].children[0].tag).equals("i")
|
o(vnode.children[0].children[0].children[0].tag).equals("i")
|
||||||
|
|
@ -402,7 +402,7 @@ o.spec("hyperscript", function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var vnode = m(component, {id: "a"}, "b")
|
var vnode = m(component, {id: "a"}, "b")
|
||||||
|
|
||||||
o(vnode.tag).equals(component)
|
o(vnode.tag).equals(component)
|
||||||
o(vnode.attrs.id).equals("a")
|
o(vnode.attrs.id).equals("a")
|
||||||
o(vnode.children.length).equals(1)
|
o(vnode.children.length).equals(1)
|
||||||
|
|
@ -410,4 +410,4 @@ o.spec("hyperscript", function() {
|
||||||
o(vnode.children[0].children).equals("b")
|
o(vnode.children[0].children).equals("b")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -22,86 +22,86 @@ o.spec("form inputs", function() {
|
||||||
var input = {tag: "input", key: 1}
|
var input = {tag: "input", key: 1}
|
||||||
var a = {tag: "a", key: 2}
|
var a = {tag: "a", key: 2}
|
||||||
var b = {tag: "b", key: 3}
|
var b = {tag: "b", key: 3}
|
||||||
|
|
||||||
render(root, [input, a, b])
|
render(root, [input, a, b])
|
||||||
input.dom.focus()
|
input.dom.focus()
|
||||||
render(root, [a, input, b])
|
render(root, [a, input, b])
|
||||||
|
|
||||||
o($window.document.activeElement).equals(input.dom)
|
o($window.document.activeElement).equals(input.dom)
|
||||||
})
|
})
|
||||||
|
|
||||||
o("syncs input value if DOM value differs from vdom value", function() {
|
o("syncs input value if DOM value differs from vdom value", function() {
|
||||||
var input = {tag: "input", attrs: {value: "aaa", oninput: function() {}}}
|
var input = {tag: "input", attrs: {value: "aaa", oninput: function() {}}}
|
||||||
var updated = {tag: "input", attrs: {value: "aaa", oninput: function() {}}}
|
var updated = {tag: "input", attrs: {value: "aaa", oninput: function() {}}}
|
||||||
|
|
||||||
render(root, [input])
|
render(root, [input])
|
||||||
|
|
||||||
//simulate user typing
|
//simulate user typing
|
||||||
var e = $window.document.createEvent("KeyboardEvent")
|
var e = $window.document.createEvent("KeyboardEvent")
|
||||||
e.initEvent("input", true, true)
|
e.initEvent("input", true, true)
|
||||||
input.dom.focus()
|
input.dom.focus()
|
||||||
input.dom.value += "a"
|
input.dom.value += "a"
|
||||||
input.dom.dispatchEvent(e)
|
input.dom.dispatchEvent(e)
|
||||||
|
|
||||||
//re-render may use same vdom value as previous render call
|
//re-render may use same vdom value as previous render call
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(updated.dom.value).equals("aaa")
|
o(updated.dom.value).equals("aaa")
|
||||||
})
|
})
|
||||||
|
|
||||||
o("syncs input checked attribute if DOM value differs from vdom value", function() {
|
o("syncs input checked attribute if DOM value differs from vdom value", function() {
|
||||||
var input = {tag: "input", attrs: {type: "checkbox", checked: true, onclick: function() {}}}
|
var input = {tag: "input", attrs: {type: "checkbox", checked: true, onclick: function() {}}}
|
||||||
var updated = {tag: "input", attrs: {type: "checkbox", checked: true, onclick: function() {}}}
|
var updated = {tag: "input", attrs: {type: "checkbox", checked: true, onclick: function() {}}}
|
||||||
|
|
||||||
render(root, [input])
|
render(root, [input])
|
||||||
|
|
||||||
//simulate user clicking checkbox
|
//simulate user clicking checkbox
|
||||||
var e = $window.document.createEvent("MouseEvents")
|
var e = $window.document.createEvent("MouseEvents")
|
||||||
e.initEvent("click", true, true)
|
e.initEvent("click", true, true)
|
||||||
input.dom.focus()
|
input.dom.focus()
|
||||||
input.dom.dispatchEvent(e)
|
input.dom.dispatchEvent(e)
|
||||||
|
|
||||||
//re-render may use same vdom value as previous render call
|
//re-render may use same vdom value as previous render call
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(updated.dom.checked).equals(true)
|
o(updated.dom.checked).equals(true)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
o.spec("select", function() {
|
o.spec("select", function() {
|
||||||
o("select works without attributes", function() {
|
o("select works without attributes", function() {
|
||||||
var select = {tag: "select", children: [
|
var select = {tag: "select", children: [
|
||||||
{tag: "option", attrs: {value: "a"}, text: "aaa"},
|
{tag: "option", attrs: {value: "a"}, text: "aaa"},
|
||||||
]}
|
]}
|
||||||
|
|
||||||
render(root, [select])
|
render(root, [select])
|
||||||
|
|
||||||
o(select.dom.value).equals("a")
|
o(select.dom.value).equals("a")
|
||||||
o(select.dom.selectedIndex).equals(0)
|
o(select.dom.selectedIndex).equals(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
o("select yields invalid value without children", function() {
|
o("select yields invalid value without children", function() {
|
||||||
var select = {tag: "select", attrs: {value: "a"}}
|
var select = {tag: "select", attrs: {value: "a"}}
|
||||||
|
|
||||||
render(root, [select])
|
render(root, [select])
|
||||||
|
|
||||||
o(select.dom.value).equals("")
|
o(select.dom.value).equals("")
|
||||||
o(select.dom.selectedIndex).equals(-1)
|
o(select.dom.selectedIndex).equals(-1)
|
||||||
})
|
})
|
||||||
|
|
||||||
o("select value is set correctly on first render", function() {
|
o("select value is set correctly on first render", function() {
|
||||||
var select = {tag: "select", attrs: {value: "b"}, children: [
|
var select = {tag: "select", attrs: {value: "b"}, children: [
|
||||||
{tag: "option", attrs: {value: "a"}, text: "aaa"},
|
{tag: "option", attrs: {value: "a"}, text: "aaa"},
|
||||||
{tag: "option", attrs: {value: "b"}, text: "bbb"},
|
{tag: "option", attrs: {value: "b"}, text: "bbb"},
|
||||||
{tag: "option", attrs: {value: "c"}, text: "ccc"},
|
{tag: "option", attrs: {value: "c"}, text: "ccc"},
|
||||||
]}
|
]}
|
||||||
|
|
||||||
render(root, [select])
|
render(root, [select])
|
||||||
|
|
||||||
o(select.dom.value).equals("b")
|
o(select.dom.value).equals("b")
|
||||||
o(select.dom.selectedIndex).equals(1)
|
o(select.dom.selectedIndex).equals(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
o("syncs select value if DOM value differs from vdom value", function() {
|
o("syncs select value if DOM value differs from vdom value", function() {
|
||||||
function makeSelect() {
|
function makeSelect() {
|
||||||
return {tag: "select", attrs: {value: "b"}, children: [
|
return {tag: "select", attrs: {value: "b"}, children: [
|
||||||
|
|
@ -110,33 +110,33 @@ o.spec("form inputs", function() {
|
||||||
{tag: "option", attrs: {value: "c"}, text: "ccc"},
|
{tag: "option", attrs: {value: "c"}, text: "ccc"},
|
||||||
]}
|
]}
|
||||||
}
|
}
|
||||||
|
|
||||||
render(root, [makeSelect()])
|
render(root, [makeSelect()])
|
||||||
|
|
||||||
//simulate user selecting option
|
//simulate user selecting option
|
||||||
root.firstChild.value = "c"
|
root.firstChild.value = "c"
|
||||||
root.firstChild.focus()
|
root.firstChild.focus()
|
||||||
|
|
||||||
//re-render may use same vdom value as previous render call
|
//re-render may use same vdom value as previous render call
|
||||||
render(root, [makeSelect()])
|
render(root, [makeSelect()])
|
||||||
|
|
||||||
o(root.firstChild.value).equals("b")
|
o(root.firstChild.value).equals("b")
|
||||||
o(root.firstChild.selectedIndex).equals(1)
|
o(root.firstChild.selectedIndex).equals(1)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
o.spec("textarea", function() {
|
o.spec("textarea", function() {
|
||||||
o("updates after user input", function() {
|
o("updates after user input", function() {
|
||||||
render(root, [{tag: "textarea", text: "aaa"}])
|
render(root, [{tag: "textarea", text: "aaa"}])
|
||||||
|
|
||||||
//simulate typing
|
//simulate typing
|
||||||
root.firstChild.value = "bbb"
|
root.firstChild.value = "bbb"
|
||||||
|
|
||||||
//re-render may occur after value attribute is touched
|
//re-render may occur after value attribute is touched
|
||||||
render(root, [{tag: "textarea", text: "ccc"}])
|
render(root, [{tag: "textarea", text: "ccc"}])
|
||||||
|
|
||||||
o(root.firstChild.value).equals("ccc")
|
o(root.firstChild.value).equals("ccc")
|
||||||
//FIXME should fail if fix is commented out
|
//FIXME should fail if fix is commented out
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,13 @@ var Node = require("../../render/node")
|
||||||
o.spec("normalize", function() {
|
o.spec("normalize", function() {
|
||||||
o("normalizes array into fragment", function() {
|
o("normalizes array into fragment", function() {
|
||||||
var node = Node.normalize([])
|
var node = Node.normalize([])
|
||||||
|
|
||||||
o(node.tag).equals("[")
|
o(node.tag).equals("[")
|
||||||
o(node.children.length).equals(0)
|
o(node.children.length).equals(0)
|
||||||
})
|
})
|
||||||
o("normalizes nested array into fragment", function() {
|
o("normalizes nested array into fragment", function() {
|
||||||
var node = Node.normalize([[]])
|
var node = Node.normalize([[]])
|
||||||
|
|
||||||
o(node.tag).equals("[")
|
o(node.tag).equals("[")
|
||||||
o(node.children.length).equals(1)
|
o(node.children.length).equals(1)
|
||||||
o(node.children[0].tag).equals("[")
|
o(node.children[0].tag).equals("[")
|
||||||
|
|
@ -20,39 +20,38 @@ o.spec("normalize", function() {
|
||||||
})
|
})
|
||||||
o("normalizes string into text node", function() {
|
o("normalizes string into text node", function() {
|
||||||
var node = Node.normalize("a")
|
var node = Node.normalize("a")
|
||||||
|
|
||||||
o(node.tag).equals("#")
|
o(node.tag).equals("#")
|
||||||
o(node.children).equals("a")
|
o(node.children).equals("a")
|
||||||
})
|
})
|
||||||
o("normalizes falsy string into text node", function() {
|
o("normalizes falsy string into text node", function() {
|
||||||
var node = Node.normalize("")
|
var node = Node.normalize("")
|
||||||
|
|
||||||
o(node.tag).equals("#")
|
o(node.tag).equals("#")
|
||||||
o(node.children).equals("")
|
o(node.children).equals("")
|
||||||
})
|
})
|
||||||
o("normalizes number into text node", function() {
|
o("normalizes number into text node", function() {
|
||||||
var node = Node.normalize(1)
|
var node = Node.normalize(1)
|
||||||
|
|
||||||
o(node.tag).equals("#")
|
o(node.tag).equals("#")
|
||||||
o(node.children).equals(1)
|
o(node.children).equals(1)
|
||||||
})
|
})
|
||||||
o("normalizes falsy number into text node", function() {
|
o("normalizes falsy number into text node", function() {
|
||||||
var node = Node.normalize(0)
|
var node = Node.normalize(0)
|
||||||
|
|
||||||
o(node.tag).equals("#")
|
o(node.tag).equals("#")
|
||||||
o(node.children).equals(0)
|
o(node.children).equals(0)
|
||||||
})
|
})
|
||||||
o("normalizes boolean into text node", function() {
|
o("normalizes boolean into text node", function() {
|
||||||
var node = Node.normalize(true)
|
var node = Node.normalize(true)
|
||||||
|
|
||||||
o(node.tag).equals("#")
|
o(node.tag).equals("#")
|
||||||
o(node.children).equals(true)
|
o(node.children).equals(true)
|
||||||
})
|
})
|
||||||
o("normalizes falsy boolean into text node", function() {
|
o("normalizes falsy boolean into text node", function() {
|
||||||
var node = Node.normalize(false)
|
var node = Node.normalize(false)
|
||||||
|
|
||||||
o(node.tag).equals("#")
|
o(node.tag).equals("#")
|
||||||
o(node.children).equals(false)
|
o(node.children).equals(false)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,15 +6,14 @@ var Node = require("../../render/node")
|
||||||
o.spec("normalizeChildren", function() {
|
o.spec("normalizeChildren", function() {
|
||||||
o("normalizes arrays into fragments", function() {
|
o("normalizes arrays into fragments", function() {
|
||||||
var children = Node.normalizeChildren([[]])
|
var children = Node.normalizeChildren([[]])
|
||||||
|
|
||||||
o(children[0].tag).equals("[")
|
o(children[0].tag).equals("[")
|
||||||
o(children[0].children.length).equals(0)
|
o(children[0].children.length).equals(0)
|
||||||
})
|
})
|
||||||
o("normalizes strings into text nodes", function() {
|
o("normalizes strings into text nodes", function() {
|
||||||
var children = Node.normalizeChildren(["a"])
|
var children = Node.normalizeChildren(["a"])
|
||||||
|
|
||||||
o(children[0].tag).equals("#")
|
o(children[0].tag).equals("#")
|
||||||
o(children[0].children).equals("a")
|
o(children[0].children).equals("a")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,9 @@ o.spec("onbeforeremove", function() {
|
||||||
var create = o.spy()
|
var create = o.spy()
|
||||||
var update = o.spy()
|
var update = o.spy()
|
||||||
var vnode = {tag: "div", attrs: {onbeforeremove: create}}
|
var vnode = {tag: "div", attrs: {onbeforeremove: create}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(create.callCount).equals(0)
|
o(create.callCount).equals(0)
|
||||||
})
|
})
|
||||||
o("does not call onbeforeremove when updating", function() {
|
o("does not call onbeforeremove when updating", function() {
|
||||||
|
|
@ -27,29 +27,29 @@ o.spec("onbeforeremove", function() {
|
||||||
var update = o.spy()
|
var update = o.spy()
|
||||||
var vnode = {tag: "div", attrs: {onbeforeremove: create}}
|
var vnode = {tag: "div", attrs: {onbeforeremove: create}}
|
||||||
var updated = {tag: "div", attrs: {onbeforeremove: update}}
|
var updated = {tag: "div", attrs: {onbeforeremove: update}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(create.callCount).equals(0)
|
o(create.callCount).equals(0)
|
||||||
o(update.callCount).equals(0)
|
o(update.callCount).equals(0)
|
||||||
})
|
})
|
||||||
o("calls onbeforeremove when removing element", function(done) {
|
o("calls onbeforeremove when removing element", function(done) {
|
||||||
var vnode = {tag: "div", attrs: {onbeforeremove: remove}}
|
var vnode = {tag: "div", attrs: {onbeforeremove: remove}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [])
|
render(root, [])
|
||||||
|
|
||||||
function remove(node, complete) {
|
function remove(node, complete) {
|
||||||
o(node).equals(vnode)
|
o(node).equals(vnode)
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
o(root.firstChild).equals(vnode.dom)
|
o(root.firstChild).equals(vnode.dom)
|
||||||
|
|
||||||
callAsync(function() {
|
callAsync(function() {
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
|
|
||||||
complete()
|
complete()
|
||||||
|
|
||||||
o(root.childNodes.length).equals(0)
|
o(root.childNodes.length).equals(0)
|
||||||
|
|
||||||
done()
|
done()
|
||||||
|
|
@ -58,20 +58,20 @@ o.spec("onbeforeremove", function() {
|
||||||
})
|
})
|
||||||
o("calls onbeforeremove when removing text", function(done) {
|
o("calls onbeforeremove when removing text", function(done) {
|
||||||
var vnode = {tag: "#", attrs: {onbeforeremove: remove}, children: "a"}
|
var vnode = {tag: "#", attrs: {onbeforeremove: remove}, children: "a"}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [])
|
render(root, [])
|
||||||
|
|
||||||
function remove(node, complete) {
|
function remove(node, complete) {
|
||||||
o(node).equals(vnode)
|
o(node).equals(vnode)
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
o(root.firstChild).equals(vnode.dom)
|
o(root.firstChild).equals(vnode.dom)
|
||||||
|
|
||||||
callAsync(function() {
|
callAsync(function() {
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
|
|
||||||
complete()
|
complete()
|
||||||
|
|
||||||
o(root.childNodes.length).equals(0)
|
o(root.childNodes.length).equals(0)
|
||||||
|
|
||||||
done()
|
done()
|
||||||
|
|
@ -80,20 +80,20 @@ o.spec("onbeforeremove", function() {
|
||||||
})
|
})
|
||||||
o("calls onbeforeremove when removing fragment", function(done) {
|
o("calls onbeforeremove when removing fragment", function(done) {
|
||||||
var vnode = {tag: "[", attrs: {onbeforeremove: remove}, children: [{tag: "div"}]}
|
var vnode = {tag: "[", attrs: {onbeforeremove: remove}, children: [{tag: "div"}]}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [])
|
render(root, [])
|
||||||
|
|
||||||
function remove(node, complete) {
|
function remove(node, complete) {
|
||||||
o(node).equals(vnode)
|
o(node).equals(vnode)
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
o(root.firstChild).equals(vnode.dom)
|
o(root.firstChild).equals(vnode.dom)
|
||||||
|
|
||||||
callAsync(function() {
|
callAsync(function() {
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
|
|
||||||
complete()
|
complete()
|
||||||
|
|
||||||
o(root.childNodes.length).equals(0)
|
o(root.childNodes.length).equals(0)
|
||||||
|
|
||||||
done()
|
done()
|
||||||
|
|
@ -102,20 +102,20 @@ o.spec("onbeforeremove", function() {
|
||||||
})
|
})
|
||||||
o("calls onbeforeremove when removing html", function(done) {
|
o("calls onbeforeremove when removing html", function(done) {
|
||||||
var vnode = {tag: "<", attrs: {onbeforeremove: remove}, children: "a"}
|
var vnode = {tag: "<", attrs: {onbeforeremove: remove}, children: "a"}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [])
|
render(root, [])
|
||||||
|
|
||||||
function remove(node, complete) {
|
function remove(node, complete) {
|
||||||
o(node).equals(vnode)
|
o(node).equals(vnode)
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
o(root.firstChild).equals(vnode.dom)
|
o(root.firstChild).equals(vnode.dom)
|
||||||
|
|
||||||
callAsync(function() {
|
callAsync(function() {
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
|
|
||||||
complete()
|
complete()
|
||||||
|
|
||||||
o(root.childNodes.length).equals(0)
|
o(root.childNodes.length).equals(0)
|
||||||
|
|
||||||
done()
|
done()
|
||||||
|
|
@ -125,21 +125,21 @@ o.spec("onbeforeremove", function() {
|
||||||
o("calls remove after onbeforeremove resolves", function(done) {
|
o("calls remove after onbeforeremove resolves", function(done) {
|
||||||
var spy = o.spy()
|
var spy = o.spy()
|
||||||
var vnode = {tag: "<", attrs: {onbeforeremove: remove, onremove: spy}, children: "a"}
|
var vnode = {tag: "<", attrs: {onbeforeremove: remove, onremove: spy}, children: "a"}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [])
|
render(root, [])
|
||||||
|
|
||||||
function remove(node, complete) {
|
function remove(node, complete) {
|
||||||
o(node).equals(vnode)
|
o(node).equals(vnode)
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
o(root.firstChild).equals(vnode.dom)
|
o(root.firstChild).equals(vnode.dom)
|
||||||
|
|
||||||
callAsync(function() {
|
callAsync(function() {
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
o(spy.callCount).equals(0)
|
o(spy.callCount).equals(0)
|
||||||
|
|
||||||
complete()
|
complete()
|
||||||
|
|
||||||
o(root.childNodes.length).equals(0)
|
o(root.childNodes.length).equals(0)
|
||||||
o(spy.callCount).equals(1)
|
o(spy.callCount).equals(1)
|
||||||
|
|
||||||
|
|
@ -150,9 +150,9 @@ o.spec("onbeforeremove", function() {
|
||||||
o("does not set onbeforeremove as an event handler", function() {
|
o("does not set onbeforeremove as an event handler", function() {
|
||||||
var remove = o.spy()
|
var remove = o.spy()
|
||||||
var vnode = {tag: "div", attrs: {onbeforeremove: remove}, children: []}
|
var vnode = {tag: "div", attrs: {onbeforeremove: remove}, children: []}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(vnode.dom.onbeforeremove).equals(undefined)
|
o(vnode.dom.onbeforeremove).equals(undefined)
|
||||||
o(vnode.dom.attributes["onbeforeremove"]).equals(undefined)
|
o(vnode.dom.attributes["onbeforeremove"]).equals(undefined)
|
||||||
})
|
})
|
||||||
|
|
@ -160,11 +160,11 @@ o.spec("onbeforeremove", function() {
|
||||||
var remove = function(vnode, done) {done()}
|
var remove = function(vnode, done) {done()}
|
||||||
var vnode = {tag: "div", key: 1, attrs: {onbeforeremove: remove}}
|
var vnode = {tag: "div", key: 1, attrs: {onbeforeremove: remove}}
|
||||||
var updated = {tag: "div", key: 1, attrs: {onbeforeremove: remove}}
|
var updated = {tag: "div", key: 1, attrs: {onbeforeremove: remove}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [])
|
render(root, [])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(vnode.dom).notEquals(updated.dom)
|
o(vnode.dom).notEquals(updated.dom)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -11,51 +11,51 @@ o.spec("onbeforeupdate", function() {
|
||||||
root = $window.document.createElement("div")
|
root = $window.document.createElement("div")
|
||||||
render = vdom($window).render
|
render = vdom($window).render
|
||||||
})
|
})
|
||||||
|
|
||||||
o("prevents update in element", function() {
|
o("prevents update in element", function() {
|
||||||
var onbeforeupdate = function() {return false}
|
var onbeforeupdate = function() {return false}
|
||||||
var vnode = {tag: "div", attrs: {id: "a", onbeforeupdate: onbeforeupdate}}
|
var vnode = {tag: "div", attrs: {id: "a", onbeforeupdate: onbeforeupdate}}
|
||||||
var updated = {tag: "div", attrs: {id: "b", onbeforeupdate: onbeforeupdate}}
|
var updated = {tag: "div", attrs: {id: "b", onbeforeupdate: onbeforeupdate}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(root.firstChild.attributes["id"].nodeValue).equals("a")
|
o(root.firstChild.attributes["id"].nodeValue).equals("a")
|
||||||
})
|
})
|
||||||
|
|
||||||
o("prevents update in text", function() {
|
o("prevents update in text", function() {
|
||||||
var onbeforeupdate = function() {return false}
|
var onbeforeupdate = function() {return false}
|
||||||
var vnode = {tag: "#", attrs: {onbeforeupdate: onbeforeupdate}, children: "a"}
|
var vnode = {tag: "#", attrs: {onbeforeupdate: onbeforeupdate}, children: "a"}
|
||||||
var updated = {tag: "#", attrs: {onbeforeupdate: onbeforeupdate}, children: "b"}
|
var updated = {tag: "#", attrs: {onbeforeupdate: onbeforeupdate}, children: "b"}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(root.firstChild.nodeValue).equals("a")
|
o(root.firstChild.nodeValue).equals("a")
|
||||||
})
|
})
|
||||||
|
|
||||||
o("prevents update in html", function() {
|
o("prevents update in html", function() {
|
||||||
var onbeforeupdate = function() {return false}
|
var onbeforeupdate = function() {return false}
|
||||||
var vnode = {tag: "<", attrs: {onbeforeupdate: onbeforeupdate}, children: "a"}
|
var vnode = {tag: "<", attrs: {onbeforeupdate: onbeforeupdate}, children: "a"}
|
||||||
var updated = {tag: "<", attrs: {onbeforeupdate: onbeforeupdate}, children: "b"}
|
var updated = {tag: "<", attrs: {onbeforeupdate: onbeforeupdate}, children: "b"}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(root.firstChild.nodeValue).equals("a")
|
o(root.firstChild.nodeValue).equals("a")
|
||||||
})
|
})
|
||||||
|
|
||||||
o("prevents update in fragment", function() {
|
o("prevents update in fragment", function() {
|
||||||
var onbeforeupdate = function() {return false}
|
var onbeforeupdate = function() {return false}
|
||||||
var vnode = {tag: "[", attrs: {onbeforeupdate: onbeforeupdate}, children: [{tag: "#", children: "a"}]}
|
var vnode = {tag: "[", attrs: {onbeforeupdate: onbeforeupdate}, children: [{tag: "#", children: "a"}]}
|
||||||
var updated = {tag: "[", attrs: {onbeforeupdate: onbeforeupdate}, children: [{tag: "#", children: "b"}]}
|
var updated = {tag: "[", attrs: {onbeforeupdate: onbeforeupdate}, children: [{tag: "#", children: "b"}]}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(root.firstChild.nodeValue).equals("a")
|
o(root.firstChild.nodeValue).equals("a")
|
||||||
})
|
})
|
||||||
|
|
||||||
o("prevents update in component", function() {
|
o("prevents update in component", function() {
|
||||||
var component = {
|
var component = {
|
||||||
onbeforeupdate: function() {return false},
|
onbeforeupdate: function() {return false},
|
||||||
|
|
@ -65,13 +65,13 @@ o.spec("onbeforeupdate", function() {
|
||||||
}
|
}
|
||||||
var vnode = {tag: component, children: [{tag: "#", children: "a"}]}
|
var vnode = {tag: component, children: [{tag: "#", children: "a"}]}
|
||||||
var updated = {tag: component, children: [{tag: "#", children: "b"}]}
|
var updated = {tag: component, children: [{tag: "#", children: "b"}]}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(root.firstChild.firstChild.nodeValue).equals("a")
|
o(root.firstChild.firstChild.nodeValue).equals("a")
|
||||||
})
|
})
|
||||||
|
|
||||||
o("prevents update if returning false in component and false in vnode", function() {
|
o("prevents update if returning false in component and false in vnode", function() {
|
||||||
var component = {
|
var component = {
|
||||||
onbeforeupdate: function() {return false},
|
onbeforeupdate: function() {return false},
|
||||||
|
|
@ -81,13 +81,13 @@ o.spec("onbeforeupdate", function() {
|
||||||
}
|
}
|
||||||
var vnode = {tag: component, attrs: {id: "a", onbeforeupdate: function() {return false}}}
|
var vnode = {tag: component, attrs: {id: "a", onbeforeupdate: function() {return false}}}
|
||||||
var updated = {tag: component, attrs: {id: "b", onbeforeupdate: function() {return false}}}
|
var updated = {tag: component, attrs: {id: "b", onbeforeupdate: function() {return false}}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(root.firstChild.attributes["id"].nodeValue).equals("a")
|
o(root.firstChild.attributes["id"].nodeValue).equals("a")
|
||||||
})
|
})
|
||||||
|
|
||||||
o("does not prevent update if returning true in component and true in vnode", function() {
|
o("does not prevent update if returning true in component and true in vnode", function() {
|
||||||
var component = {
|
var component = {
|
||||||
onbeforeupdate: function() {return true},
|
onbeforeupdate: function() {return true},
|
||||||
|
|
@ -97,13 +97,13 @@ o.spec("onbeforeupdate", function() {
|
||||||
}
|
}
|
||||||
var vnode = {tag: component, attrs: {id: "a", onbeforeupdate: function() {return true}}}
|
var vnode = {tag: component, attrs: {id: "a", onbeforeupdate: function() {return true}}}
|
||||||
var updated = {tag: component, attrs: {id: "b", onbeforeupdate: function() {return true}}}
|
var updated = {tag: component, attrs: {id: "b", onbeforeupdate: function() {return true}}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(root.firstChild.attributes["id"].nodeValue).equals("b")
|
o(root.firstChild.attributes["id"].nodeValue).equals("b")
|
||||||
})
|
})
|
||||||
|
|
||||||
o("does not prevent update if returning false in component but true in vnode", function() {
|
o("does not prevent update if returning false in component but true in vnode", function() {
|
||||||
var component = {
|
var component = {
|
||||||
onbeforeupdate: function() {return false},
|
onbeforeupdate: function() {return false},
|
||||||
|
|
@ -113,13 +113,13 @@ o.spec("onbeforeupdate", function() {
|
||||||
}
|
}
|
||||||
var vnode = {tag: component, attrs: {id: "a", onbeforeupdate: function() {return true}}}
|
var vnode = {tag: component, attrs: {id: "a", onbeforeupdate: function() {return true}}}
|
||||||
var updated = {tag: component, attrs: {id: "b", onbeforeupdate: function() {return true}}}
|
var updated = {tag: component, attrs: {id: "b", onbeforeupdate: function() {return true}}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(root.firstChild.attributes["id"].nodeValue).equals("b")
|
o(root.firstChild.attributes["id"].nodeValue).equals("b")
|
||||||
})
|
})
|
||||||
|
|
||||||
o("does not prevent update if returning true in component but false in vnode", function() {
|
o("does not prevent update if returning true in component but false in vnode", function() {
|
||||||
var component = {
|
var component = {
|
||||||
onbeforeupdate: function() {return true},
|
onbeforeupdate: function() {return true},
|
||||||
|
|
@ -129,24 +129,24 @@ o.spec("onbeforeupdate", function() {
|
||||||
}
|
}
|
||||||
var vnode = {tag: component, attrs: {id: "a", onbeforeupdate: function() {return false}}}
|
var vnode = {tag: component, attrs: {id: "a", onbeforeupdate: function() {return false}}}
|
||||||
var updated = {tag: component, attrs: {id: "b", onbeforeupdate: function() {return false}}}
|
var updated = {tag: component, attrs: {id: "b", onbeforeupdate: function() {return false}}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(root.firstChild.attributes["id"].nodeValue).equals("b")
|
o(root.firstChild.attributes["id"].nodeValue).equals("b")
|
||||||
})
|
})
|
||||||
|
|
||||||
o("does not prevent update if returning true", function() {
|
o("does not prevent update if returning true", function() {
|
||||||
var onbeforeupdate = function() {return true}
|
var onbeforeupdate = function() {return true}
|
||||||
var vnode = {tag: "div", attrs: {id: "a", onbeforeupdate: onbeforeupdate}}
|
var vnode = {tag: "div", attrs: {id: "a", onbeforeupdate: onbeforeupdate}}
|
||||||
var updated = {tag: "div", attrs: {id: "b", onbeforeupdate: onbeforeupdate}}
|
var updated = {tag: "div", attrs: {id: "b", onbeforeupdate: onbeforeupdate}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(root.firstChild.attributes["id"].nodeValue).equals("b")
|
o(root.firstChild.attributes["id"].nodeValue).equals("b")
|
||||||
})
|
})
|
||||||
|
|
||||||
o("does not prevent update if returning true from component", function() {
|
o("does not prevent update if returning true from component", function() {
|
||||||
var component = {
|
var component = {
|
||||||
onbeforeupdate: function() {return true},
|
onbeforeupdate: function() {return true},
|
||||||
|
|
@ -156,34 +156,34 @@ o.spec("onbeforeupdate", function() {
|
||||||
}
|
}
|
||||||
var vnode = {tag: component, attrs: {id: "a"}}
|
var vnode = {tag: component, attrs: {id: "a"}}
|
||||||
var updated = {tag: component, attrs: {id: "b"}}
|
var updated = {tag: component, attrs: {id: "b"}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(root.firstChild.attributes["id"].nodeValue).equals("b")
|
o(root.firstChild.attributes["id"].nodeValue).equals("b")
|
||||||
})
|
})
|
||||||
|
|
||||||
o("accepts arguments for comparison", function() {
|
o("accepts arguments for comparison", function() {
|
||||||
var count = 0
|
var count = 0
|
||||||
var vnode = {tag: "div", attrs: {id: "a", onbeforeupdate: onbeforeupdate}}
|
var vnode = {tag: "div", attrs: {id: "a", onbeforeupdate: onbeforeupdate}}
|
||||||
var updated = {tag: "div", attrs: {id: "b", onbeforeupdate: onbeforeupdate}}
|
var updated = {tag: "div", attrs: {id: "b", onbeforeupdate: onbeforeupdate}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
function onbeforeupdate(vnode, old) {
|
function onbeforeupdate(vnode, old) {
|
||||||
count++
|
count++
|
||||||
|
|
||||||
o(old.attrs.id).equals("a")
|
o(old.attrs.id).equals("a")
|
||||||
o(vnode.attrs.id).equals("b")
|
o(vnode.attrs.id).equals("b")
|
||||||
|
|
||||||
return old.attrs.id !== vnode.attrs.id
|
return old.attrs.id !== vnode.attrs.id
|
||||||
}
|
}
|
||||||
|
|
||||||
o(count).equals(1)
|
o(count).equals(1)
|
||||||
o(root.firstChild.attributes["id"].nodeValue).equals("b")
|
o(root.firstChild.attributes["id"].nodeValue).equals("b")
|
||||||
})
|
})
|
||||||
|
|
||||||
o("accepts arguments for comparison in component", function() {
|
o("accepts arguments for comparison in component", function() {
|
||||||
var component = {
|
var component = {
|
||||||
onbeforeupdate: onbeforeupdate,
|
onbeforeupdate: onbeforeupdate,
|
||||||
|
|
@ -194,38 +194,38 @@ o.spec("onbeforeupdate", function() {
|
||||||
var count = 0
|
var count = 0
|
||||||
var vnode = {tag: component, attrs: {id: "a"}}
|
var vnode = {tag: component, attrs: {id: "a"}}
|
||||||
var updated = {tag: component, attrs: {id: "b"}}
|
var updated = {tag: component, attrs: {id: "b"}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
function onbeforeupdate(vnode, old) {
|
function onbeforeupdate(vnode, old) {
|
||||||
count++
|
count++
|
||||||
|
|
||||||
o(old.attrs.id).equals("a")
|
o(old.attrs.id).equals("a")
|
||||||
o(vnode.attrs.id).equals("b")
|
o(vnode.attrs.id).equals("b")
|
||||||
|
|
||||||
return old.attrs.id !== vnode.attrs.id
|
return old.attrs.id !== vnode.attrs.id
|
||||||
}
|
}
|
||||||
|
|
||||||
o(count).equals(1)
|
o(count).equals(1)
|
||||||
o(root.firstChild.attributes["id"].nodeValue).equals("b")
|
o(root.firstChild.attributes["id"].nodeValue).equals("b")
|
||||||
})
|
})
|
||||||
|
|
||||||
o("is not called on creation", function() {
|
o("is not called on creation", function() {
|
||||||
var count = 0
|
var count = 0
|
||||||
var vnode = {tag: "div", attrs: {id: "a", onbeforeupdate: onbeforeupdate}}
|
var vnode = {tag: "div", attrs: {id: "a", onbeforeupdate: onbeforeupdate}}
|
||||||
var updated = {tag: "div", attrs: {id: "b", onbeforeupdate: onbeforeupdate}}
|
var updated = {tag: "div", attrs: {id: "b", onbeforeupdate: onbeforeupdate}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
function onbeforeupdate(vnode, old) {
|
function onbeforeupdate(vnode, old) {
|
||||||
count++
|
count++
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
o(count).equals(0)
|
o(count).equals(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
o("is not called on component creation", function() {
|
o("is not called on component creation", function() {
|
||||||
var component = {
|
var component = {
|
||||||
onbeforeupdate: onbeforeupdate,
|
onbeforeupdate: onbeforeupdate,
|
||||||
|
|
@ -233,37 +233,37 @@ o.spec("onbeforeupdate", function() {
|
||||||
return {tag: "div", attrs: vnode.attrs}
|
return {tag: "div", attrs: vnode.attrs}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var count = 0
|
var count = 0
|
||||||
var vnode = {tag: "div", attrs: {id: "a"}}
|
var vnode = {tag: "div", attrs: {id: "a"}}
|
||||||
var updated = {tag: "div", attrs: {id: "b"}}
|
var updated = {tag: "div", attrs: {id: "b"}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
function onbeforeupdate(vnode, old) {
|
function onbeforeupdate(vnode, old) {
|
||||||
count++
|
count++
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
o(count).equals(0)
|
o(count).equals(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
o("is called only once on update", function() {
|
o("is called only once on update", function() {
|
||||||
var count = 0
|
var count = 0
|
||||||
var vnode = {tag: "div", attrs: {id: "a", onbeforeupdate: onbeforeupdate}}
|
var vnode = {tag: "div", attrs: {id: "a", onbeforeupdate: onbeforeupdate}}
|
||||||
var updated = {tag: "div", attrs: {id: "b", onbeforeupdate: onbeforeupdate}}
|
var updated = {tag: "div", attrs: {id: "b", onbeforeupdate: onbeforeupdate}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
function onbeforeupdate(vnode, old) {
|
function onbeforeupdate(vnode, old) {
|
||||||
count++
|
count++
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
o(count).equals(1)
|
o(count).equals(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
o("is called only once on component update", function() {
|
o("is called only once on component update", function() {
|
||||||
var component = {
|
var component = {
|
||||||
onbeforeupdate: onbeforeupdate,
|
onbeforeupdate: onbeforeupdate,
|
||||||
|
|
@ -271,19 +271,19 @@ o.spec("onbeforeupdate", function() {
|
||||||
return {tag: "div", attrs: vnode.attrs}
|
return {tag: "div", attrs: vnode.attrs}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var count = 0
|
var count = 0
|
||||||
var vnode = {tag: component, attrs: {id: "a"}}
|
var vnode = {tag: component, attrs: {id: "a"}}
|
||||||
var updated = {tag: component, attrs: {id: "b"}}
|
var updated = {tag: component, attrs: {id: "b"}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
function onbeforeupdate(vnode, old) {
|
function onbeforeupdate(vnode, old) {
|
||||||
count++
|
count++
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
o(count).equals(1)
|
o(count).equals(1)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,9 @@ o.spec("oncreate", function() {
|
||||||
o("calls oncreate when creating element", function() {
|
o("calls oncreate when creating element", function() {
|
||||||
var callback = o.spy()
|
var callback = o.spy()
|
||||||
var vnode = {tag: "div", attrs: {oncreate: callback}, state: {}}
|
var vnode = {tag: "div", attrs: {oncreate: callback}, state: {}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(callback.callCount).equals(1)
|
o(callback.callCount).equals(1)
|
||||||
o(callback.this).equals(vnode.state)
|
o(callback.this).equals(vnode.state)
|
||||||
o(callback.args[0]).equals(vnode)
|
o(callback.args[0]).equals(vnode)
|
||||||
|
|
@ -25,9 +25,9 @@ o.spec("oncreate", function() {
|
||||||
o("calls oncreate when creating text", function() {
|
o("calls oncreate when creating text", function() {
|
||||||
var callback = o.spy()
|
var callback = o.spy()
|
||||||
var vnode = {tag: "#", attrs: {oncreate: callback}, children: "a", state: {}}
|
var vnode = {tag: "#", attrs: {oncreate: callback}, children: "a", state: {}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(callback.callCount).equals(1)
|
o(callback.callCount).equals(1)
|
||||||
o(callback.this).equals(vnode.state)
|
o(callback.this).equals(vnode.state)
|
||||||
o(callback.args[0]).equals(vnode)
|
o(callback.args[0]).equals(vnode)
|
||||||
|
|
@ -35,9 +35,9 @@ o.spec("oncreate", function() {
|
||||||
o("calls oncreate when creating fragment", function() {
|
o("calls oncreate when creating fragment", function() {
|
||||||
var callback = o.spy()
|
var callback = o.spy()
|
||||||
var vnode = {tag: "[", attrs: {oncreate: callback}, children: [], state: {}}
|
var vnode = {tag: "[", attrs: {oncreate: callback}, children: [], state: {}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(callback.callCount).equals(1)
|
o(callback.callCount).equals(1)
|
||||||
o(callback.this).equals(vnode.state)
|
o(callback.this).equals(vnode.state)
|
||||||
o(callback.args[0]).equals(vnode)
|
o(callback.args[0]).equals(vnode)
|
||||||
|
|
@ -45,9 +45,9 @@ o.spec("oncreate", function() {
|
||||||
o("calls oncreate when creating html", function() {
|
o("calls oncreate when creating html", function() {
|
||||||
var callback = o.spy()
|
var callback = o.spy()
|
||||||
var vnode = {tag: "<", attrs: {oncreate: callback}, children: "a", state: {}}
|
var vnode = {tag: "<", attrs: {oncreate: callback}, children: "a", state: {}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(callback.callCount).equals(1)
|
o(callback.callCount).equals(1)
|
||||||
o(callback.this).equals(vnode.state)
|
o(callback.this).equals(vnode.state)
|
||||||
o(callback.args[0]).equals(vnode)
|
o(callback.args[0]).equals(vnode)
|
||||||
|
|
@ -57,10 +57,10 @@ o.spec("oncreate", function() {
|
||||||
var createA = o.spy()
|
var createA = o.spy()
|
||||||
var vnode = {tag: "div", key: 1, attrs: {oncreate: createDiv}, state: {}}
|
var vnode = {tag: "div", key: 1, attrs: {oncreate: createDiv}, state: {}}
|
||||||
var updated = {tag: "a", key: 1, attrs: {oncreate: createA}, state: {}}
|
var updated = {tag: "a", key: 1, attrs: {oncreate: createA}, state: {}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(createDiv.callCount).equals(1)
|
o(createDiv.callCount).equals(1)
|
||||||
o(createDiv.this).equals(vnode.state)
|
o(createDiv.this).equals(vnode.state)
|
||||||
o(createDiv.args[0]).equals(vnode)
|
o(createDiv.args[0]).equals(vnode)
|
||||||
|
|
@ -73,10 +73,10 @@ o.spec("oncreate", function() {
|
||||||
var update = o.spy()
|
var update = o.spy()
|
||||||
var vnode = {tag: "div", attrs: {oncreate: create}, state: {}}
|
var vnode = {tag: "div", attrs: {oncreate: create}, state: {}}
|
||||||
var updated = {tag: "div", attrs: {oncreate: update}, state: {}}
|
var updated = {tag: "div", attrs: {oncreate: update}, state: {}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(create.callCount).equals(1)
|
o(create.callCount).equals(1)
|
||||||
o(create.this).equals(vnode.state)
|
o(create.this).equals(vnode.state)
|
||||||
o(create.args[0]).equals(vnode)
|
o(create.args[0]).equals(vnode)
|
||||||
|
|
@ -87,10 +87,10 @@ o.spec("oncreate", function() {
|
||||||
var update = o.spy()
|
var update = o.spy()
|
||||||
var vnode = {tag: "div", attrs: {oncreate: create}, state: {}}
|
var vnode = {tag: "div", attrs: {oncreate: create}, state: {}}
|
||||||
var updated = {tag: "div", attrs: {oncreate: update, id: "a"}, state: {}}
|
var updated = {tag: "div", attrs: {oncreate: update, id: "a"}, state: {}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(create.callCount).equals(1)
|
o(create.callCount).equals(1)
|
||||||
o(create.this).equals(vnode.state)
|
o(create.this).equals(vnode.state)
|
||||||
o(create.args[0]).equals(vnode)
|
o(create.args[0]).equals(vnode)
|
||||||
|
|
@ -101,10 +101,10 @@ o.spec("oncreate", function() {
|
||||||
var update = o.spy()
|
var update = o.spy()
|
||||||
var vnode = {tag: "div", attrs: {oncreate: create}, children: [{tag: "a"}], state: {}}
|
var vnode = {tag: "div", attrs: {oncreate: create}, children: [{tag: "a"}], state: {}}
|
||||||
var updated = {tag: "div", attrs: {oncreate: update}, children: [{tag: "b"}], state: {}}
|
var updated = {tag: "div", attrs: {oncreate: update}, children: [{tag: "b"}], state: {}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(create.callCount).equals(1)
|
o(create.callCount).equals(1)
|
||||||
o(create.this).equals(vnode.state)
|
o(create.this).equals(vnode.state)
|
||||||
o(create.args[0]).equals(vnode)
|
o(create.args[0]).equals(vnode)
|
||||||
|
|
@ -117,10 +117,10 @@ o.spec("oncreate", function() {
|
||||||
var otherVnode = {tag: "a", key: 2}
|
var otherVnode = {tag: "a", key: 2}
|
||||||
var updated = {tag: "div", key: 1, attrs: {oncreate: update}, state: {}}
|
var updated = {tag: "div", key: 1, attrs: {oncreate: update}, state: {}}
|
||||||
var otherUpdated = {tag: "a", key: 2}
|
var otherUpdated = {tag: "a", key: 2}
|
||||||
|
|
||||||
render(root, [vnode, otherVnode])
|
render(root, [vnode, otherVnode])
|
||||||
render(root, [otherUpdated, updated])
|
render(root, [otherUpdated, updated])
|
||||||
|
|
||||||
o(create.callCount).equals(1)
|
o(create.callCount).equals(1)
|
||||||
o(create.this).equals(vnode.state)
|
o(create.this).equals(vnode.state)
|
||||||
o(create.args[0]).equals(vnode)
|
o(create.args[0]).equals(vnode)
|
||||||
|
|
@ -130,10 +130,10 @@ o.spec("oncreate", function() {
|
||||||
var create = o.spy()
|
var create = o.spy()
|
||||||
var update = o.spy()
|
var update = o.spy()
|
||||||
var vnode = {tag: "div", attrs: {oncreate: create}, state: {}}
|
var vnode = {tag: "div", attrs: {oncreate: create}, state: {}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [])
|
render(root, [])
|
||||||
|
|
||||||
o(create.callCount).equals(1)
|
o(create.callCount).equals(1)
|
||||||
o(create.this).equals(vnode.state)
|
o(create.this).equals(vnode.state)
|
||||||
o(create.args[0]).equals(vnode)
|
o(create.args[0]).equals(vnode)
|
||||||
|
|
@ -143,11 +143,11 @@ o.spec("oncreate", function() {
|
||||||
var update = o.spy()
|
var update = o.spy()
|
||||||
var vnode = {tag: "div", key: 1, attrs: {oncreate: create}, state: {}}
|
var vnode = {tag: "div", key: 1, attrs: {oncreate: create}, state: {}}
|
||||||
var updated = {tag: "div", key: 1, attrs: {oncreate: update}, state: {}}
|
var updated = {tag: "div", key: 1, attrs: {oncreate: update}, state: {}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [])
|
render(root, [])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(vnode.dom).notEquals(updated.dom)
|
o(vnode.dom).notEquals(updated.dom)
|
||||||
o(create.callCount).equals(1)
|
o(create.callCount).equals(1)
|
||||||
o(create.this).equals(vnode.state)
|
o(create.this).equals(vnode.state)
|
||||||
|
|
@ -162,10 +162,10 @@ o.spec("oncreate", function() {
|
||||||
var callback = o.spy()
|
var callback = o.spy()
|
||||||
var vnode = {tag: "div", attrs: {onupdate: create}, children: [], state: {}}
|
var vnode = {tag: "div", attrs: {onupdate: create}, children: [], state: {}}
|
||||||
var updated = {tag: "div", attrs: {onupdate: update}, children: [{tag: "a", attrs: {oncreate: callback}, state: {}}], state: {}}
|
var updated = {tag: "div", attrs: {onupdate: update}, children: [{tag: "a", attrs: {oncreate: callback}, state: {}}], state: {}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(create.callCount).equals(0)
|
o(create.callCount).equals(0)
|
||||||
o(update.callCount).equals(1)
|
o(update.callCount).equals(1)
|
||||||
o(update.this).equals(vnode.state)
|
o(update.this).equals(vnode.state)
|
||||||
|
|
@ -181,12 +181,12 @@ o.spec("oncreate", function() {
|
||||||
{tag: "b"}
|
{tag: "b"}
|
||||||
]}
|
]}
|
||||||
]}
|
]}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
function create(vnode) {
|
function create(vnode) {
|
||||||
created = true
|
created = true
|
||||||
|
|
||||||
o(vnode.dom.parentNode).notEquals(null)
|
o(vnode.dom.parentNode).notEquals(null)
|
||||||
o(vnode.dom.childNodes.length).equals(1)
|
o(vnode.dom.childNodes.length).equals(1)
|
||||||
}
|
}
|
||||||
|
|
@ -195,9 +195,9 @@ o.spec("oncreate", function() {
|
||||||
o("does not set oncreate as an event handler", function() {
|
o("does not set oncreate as an event handler", function() {
|
||||||
var create = o.spy()
|
var create = o.spy()
|
||||||
var vnode = {tag: "div", attrs: {oncreate: create}, children: []}
|
var vnode = {tag: "div", attrs: {oncreate: create}, children: []}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(vnode.dom.oncreate).equals(undefined)
|
o(vnode.dom.oncreate).equals(undefined)
|
||||||
o(vnode.dom.attributes["oncreate"]).equals(undefined)
|
o(vnode.dom.attributes["oncreate"]).equals(undefined)
|
||||||
})
|
})
|
||||||
|
|
@ -206,11 +206,11 @@ o.spec("oncreate", function() {
|
||||||
var vnodes = [{tag: "div", key: 1, attrs: {oncreate: create}}]
|
var vnodes = [{tag: "div", key: 1, attrs: {oncreate: create}}]
|
||||||
var temp = []
|
var temp = []
|
||||||
var updated = [{tag: "div", key: 1, attrs: {oncreate: create}}]
|
var updated = [{tag: "div", key: 1, attrs: {oncreate: create}}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, temp)
|
render(root, temp)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(create.callCount).equals(2)
|
o(create.callCount).equals(2)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,9 @@ o.spec("oninit", function() {
|
||||||
o("calls oninit when creating element", function() {
|
o("calls oninit when creating element", function() {
|
||||||
var callback = o.spy()
|
var callback = o.spy()
|
||||||
var vnode = {tag: "div", attrs: {oninit: callback}, state: {}}
|
var vnode = {tag: "div", attrs: {oninit: callback}, state: {}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(callback.callCount).equals(1)
|
o(callback.callCount).equals(1)
|
||||||
o(callback.this).equals(vnode.state)
|
o(callback.this).equals(vnode.state)
|
||||||
o(callback.args[0]).equals(vnode)
|
o(callback.args[0]).equals(vnode)
|
||||||
|
|
@ -25,9 +25,9 @@ o.spec("oninit", function() {
|
||||||
o("calls oninit when creating text", function() {
|
o("calls oninit when creating text", function() {
|
||||||
var callback = o.spy()
|
var callback = o.spy()
|
||||||
var vnode = {tag: "#", attrs: {oninit: callback}, children: "a", state: {}}
|
var vnode = {tag: "#", attrs: {oninit: callback}, children: "a", state: {}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(callback.callCount).equals(1)
|
o(callback.callCount).equals(1)
|
||||||
o(callback.this).equals(vnode.state)
|
o(callback.this).equals(vnode.state)
|
||||||
o(callback.args[0]).equals(vnode)
|
o(callback.args[0]).equals(vnode)
|
||||||
|
|
@ -35,9 +35,9 @@ o.spec("oninit", function() {
|
||||||
o("calls oninit when creating fragment", function() {
|
o("calls oninit when creating fragment", function() {
|
||||||
var callback = o.spy()
|
var callback = o.spy()
|
||||||
var vnode = {tag: "[", attrs: {oninit: callback}, children: [], state: {}}
|
var vnode = {tag: "[", attrs: {oninit: callback}, children: [], state: {}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(callback.callCount).equals(1)
|
o(callback.callCount).equals(1)
|
||||||
o(callback.this).equals(vnode.state)
|
o(callback.this).equals(vnode.state)
|
||||||
o(callback.args[0]).equals(vnode)
|
o(callback.args[0]).equals(vnode)
|
||||||
|
|
@ -45,9 +45,9 @@ o.spec("oninit", function() {
|
||||||
o("calls oninit when creating html", function() {
|
o("calls oninit when creating html", function() {
|
||||||
var callback = o.spy()
|
var callback = o.spy()
|
||||||
var vnode = {tag: "<", attrs: {oninit: callback}, children: "a", state: {}}
|
var vnode = {tag: "<", attrs: {oninit: callback}, children: "a", state: {}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(callback.callCount).equals(1)
|
o(callback.callCount).equals(1)
|
||||||
o(callback.this).equals(vnode.state)
|
o(callback.this).equals(vnode.state)
|
||||||
o(callback.args[0]).equals(vnode)
|
o(callback.args[0]).equals(vnode)
|
||||||
|
|
@ -57,10 +57,10 @@ o.spec("oninit", function() {
|
||||||
var createA = o.spy()
|
var createA = o.spy()
|
||||||
var vnode = {tag: "div", key: 1, attrs: {oninit: createDiv}, state: {}}
|
var vnode = {tag: "div", key: 1, attrs: {oninit: createDiv}, state: {}}
|
||||||
var updated = {tag: "a", key: 1, attrs: {oninit: createA}, state: {}}
|
var updated = {tag: "a", key: 1, attrs: {oninit: createA}, state: {}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(createDiv.callCount).equals(1)
|
o(createDiv.callCount).equals(1)
|
||||||
o(createDiv.this).equals(vnode.state)
|
o(createDiv.this).equals(vnode.state)
|
||||||
o(createDiv.args[0]).equals(vnode)
|
o(createDiv.args[0]).equals(vnode)
|
||||||
|
|
@ -73,10 +73,10 @@ o.spec("oninit", function() {
|
||||||
var update = o.spy()
|
var update = o.spy()
|
||||||
var vnode = {tag: "div", attrs: {oninit: create}, state: {}}
|
var vnode = {tag: "div", attrs: {oninit: create}, state: {}}
|
||||||
var updated = {tag: "div", attrs: {oninit: update}, state: {}}
|
var updated = {tag: "div", attrs: {oninit: update}, state: {}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(create.callCount).equals(1)
|
o(create.callCount).equals(1)
|
||||||
o(create.this).equals(vnode.state)
|
o(create.this).equals(vnode.state)
|
||||||
o(create.args[0]).equals(vnode)
|
o(create.args[0]).equals(vnode)
|
||||||
|
|
@ -87,10 +87,10 @@ o.spec("oninit", function() {
|
||||||
var update = o.spy()
|
var update = o.spy()
|
||||||
var vnode = {tag: "div", attrs: {oninit: create}, state: {}}
|
var vnode = {tag: "div", attrs: {oninit: create}, state: {}}
|
||||||
var updated = {tag: "div", attrs: {oninit: update, id: "a"}, state: {}}
|
var updated = {tag: "div", attrs: {oninit: update, id: "a"}, state: {}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(create.callCount).equals(1)
|
o(create.callCount).equals(1)
|
||||||
o(create.this).equals(vnode.state)
|
o(create.this).equals(vnode.state)
|
||||||
o(create.args[0]).equals(vnode)
|
o(create.args[0]).equals(vnode)
|
||||||
|
|
@ -101,10 +101,10 @@ o.spec("oninit", function() {
|
||||||
var update = o.spy()
|
var update = o.spy()
|
||||||
var vnode = {tag: "div", attrs: {oninit: create}, children: [{tag: "a"}], state: {}}
|
var vnode = {tag: "div", attrs: {oninit: create}, children: [{tag: "a"}], state: {}}
|
||||||
var updated = {tag: "div", attrs: {oninit: update}, children: [{tag: "b"}], state: {}}
|
var updated = {tag: "div", attrs: {oninit: update}, children: [{tag: "b"}], state: {}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(create.callCount).equals(1)
|
o(create.callCount).equals(1)
|
||||||
o(create.this).equals(vnode.state)
|
o(create.this).equals(vnode.state)
|
||||||
o(create.args[0]).equals(vnode)
|
o(create.args[0]).equals(vnode)
|
||||||
|
|
@ -117,10 +117,10 @@ o.spec("oninit", function() {
|
||||||
var otherVnode = {tag: "a", key: 2}
|
var otherVnode = {tag: "a", key: 2}
|
||||||
var updated = {tag: "div", key: 1, attrs: {oninit: update}, state: {}}
|
var updated = {tag: "div", key: 1, attrs: {oninit: update}, state: {}}
|
||||||
var otherUpdated = {tag: "a", key: 2}
|
var otherUpdated = {tag: "a", key: 2}
|
||||||
|
|
||||||
render(root, [vnode, otherVnode])
|
render(root, [vnode, otherVnode])
|
||||||
render(root, [otherUpdated, updated])
|
render(root, [otherUpdated, updated])
|
||||||
|
|
||||||
o(create.callCount).equals(1)
|
o(create.callCount).equals(1)
|
||||||
o(create.this).equals(vnode.state)
|
o(create.this).equals(vnode.state)
|
||||||
o(create.args[0]).equals(vnode)
|
o(create.args[0]).equals(vnode)
|
||||||
|
|
@ -130,10 +130,10 @@ o.spec("oninit", function() {
|
||||||
var create = o.spy()
|
var create = o.spy()
|
||||||
var update = o.spy()
|
var update = o.spy()
|
||||||
var vnode = {tag: "div", attrs: {oninit: create}, state: {}}
|
var vnode = {tag: "div", attrs: {oninit: create}, state: {}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [])
|
render(root, [])
|
||||||
|
|
||||||
o(create.callCount).equals(1)
|
o(create.callCount).equals(1)
|
||||||
o(create.this).equals(vnode.state)
|
o(create.this).equals(vnode.state)
|
||||||
o(create.args[0]).equals(vnode)
|
o(create.args[0]).equals(vnode)
|
||||||
|
|
@ -143,11 +143,11 @@ o.spec("oninit", function() {
|
||||||
var update = o.spy()
|
var update = o.spy()
|
||||||
var vnode = {tag: "div", key: 1, attrs: {oninit: create}, state: {}}
|
var vnode = {tag: "div", key: 1, attrs: {oninit: create}, state: {}}
|
||||||
var updated = {tag: "div", key: 1, attrs: {oninit: update}, state: {}}
|
var updated = {tag: "div", key: 1, attrs: {oninit: update}, state: {}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [])
|
render(root, [])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(vnode.dom).equals(updated.dom)
|
o(vnode.dom).equals(updated.dom)
|
||||||
o(create.callCount).equals(1)
|
o(create.callCount).equals(1)
|
||||||
o(create.this).equals(vnode.state)
|
o(create.this).equals(vnode.state)
|
||||||
|
|
@ -162,10 +162,10 @@ o.spec("oninit", function() {
|
||||||
var callback = o.spy()
|
var callback = o.spy()
|
||||||
var vnode = {tag: "div", attrs: {onupdate: create}, children: [], state: {}}
|
var vnode = {tag: "div", attrs: {onupdate: create}, children: [], state: {}}
|
||||||
var updated = {tag: "div", attrs: {onupdate: update}, children: [{tag: "a", attrs: {oninit: callback}, state: {}}], state: {}}
|
var updated = {tag: "div", attrs: {onupdate: update}, children: [{tag: "a", attrs: {oninit: callback}, state: {}}], state: {}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(create.callCount).equals(0)
|
o(create.callCount).equals(0)
|
||||||
o(update.callCount).equals(1)
|
o(update.callCount).equals(1)
|
||||||
o(update.this).equals(vnode.state)
|
o(update.this).equals(vnode.state)
|
||||||
|
|
@ -181,12 +181,12 @@ o.spec("oninit", function() {
|
||||||
{tag: "b"}
|
{tag: "b"}
|
||||||
]}
|
]}
|
||||||
]}
|
]}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
function create(vnode) {
|
function create(vnode) {
|
||||||
called = true
|
called = true
|
||||||
|
|
||||||
o(vnode.dom).equals(undefined)
|
o(vnode.dom).equals(undefined)
|
||||||
o(root.childNodes.length).equals(0)
|
o(root.childNodes.length).equals(0)
|
||||||
}
|
}
|
||||||
|
|
@ -195,9 +195,9 @@ o.spec("oninit", function() {
|
||||||
o("does not set oninit as an event handler", function() {
|
o("does not set oninit as an event handler", function() {
|
||||||
var create = o.spy()
|
var create = o.spy()
|
||||||
var vnode = {tag: "div", attrs: {oninit: create}, children: []}
|
var vnode = {tag: "div", attrs: {oninit: create}, children: []}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(vnode.dom.oninit).equals(undefined)
|
o(vnode.dom.oninit).equals(undefined)
|
||||||
o(vnode.dom.attributes["oninit"]).equals(undefined)
|
o(vnode.dom.attributes["oninit"]).equals(undefined)
|
||||||
})
|
})
|
||||||
|
|
@ -206,11 +206,11 @@ o.spec("oninit", function() {
|
||||||
var vnodes = [{tag: "div", key: 1, attrs: {oninit: create}}]
|
var vnodes = [{tag: "div", key: 1, attrs: {oninit: create}}]
|
||||||
var temp = []
|
var temp = []
|
||||||
var updated = [{tag: "div", key: 1, attrs: {oninit: create}}]
|
var updated = [{tag: "div", key: 1, attrs: {oninit: create}}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, temp)
|
render(root, temp)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(create.callCount).equals(2)
|
o(create.callCount).equals(2)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,10 @@ o.spec("onremove", function() {
|
||||||
var update = o.spy()
|
var update = o.spy()
|
||||||
var vnode = {tag: "div", attrs: {onremove: create}}
|
var vnode = {tag: "div", attrs: {onremove: create}}
|
||||||
var updated = {tag: "div", attrs: {onremove: update}}
|
var updated = {tag: "div", attrs: {onremove: update}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(create.callCount).equals(0)
|
o(create.callCount).equals(0)
|
||||||
})
|
})
|
||||||
o("does not call onremove when updating", function() {
|
o("does not call onremove when updating", function() {
|
||||||
|
|
@ -28,20 +28,20 @@ o.spec("onremove", function() {
|
||||||
var update = o.spy()
|
var update = o.spy()
|
||||||
var vnode = {tag: "div", attrs: {onremove: create}}
|
var vnode = {tag: "div", attrs: {onremove: create}}
|
||||||
var updated = {tag: "div", attrs: {onremove: update}}
|
var updated = {tag: "div", attrs: {onremove: update}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(create.callCount).equals(0)
|
o(create.callCount).equals(0)
|
||||||
o(update.callCount).equals(0)
|
o(update.callCount).equals(0)
|
||||||
})
|
})
|
||||||
o("calls onremove when removing element", function() {
|
o("calls onremove when removing element", function() {
|
||||||
var remove = o.spy()
|
var remove = o.spy()
|
||||||
var vnode = {tag: "div", attrs: {onremove: remove}, state: {}}
|
var vnode = {tag: "div", attrs: {onremove: remove}, state: {}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [])
|
render(root, [])
|
||||||
|
|
||||||
o(remove.callCount).equals(1)
|
o(remove.callCount).equals(1)
|
||||||
o(remove.this).equals(vnode.state)
|
o(remove.this).equals(vnode.state)
|
||||||
o(remove.args[0]).equals(vnode)
|
o(remove.args[0]).equals(vnode)
|
||||||
|
|
@ -49,10 +49,10 @@ o.spec("onremove", function() {
|
||||||
o("calls onremove when removing text", function() {
|
o("calls onremove when removing text", function() {
|
||||||
var remove = o.spy()
|
var remove = o.spy()
|
||||||
var vnode = {tag: "#", attrs: {onremove: remove}, children: "a", state: {}}
|
var vnode = {tag: "#", attrs: {onremove: remove}, children: "a", state: {}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [])
|
render(root, [])
|
||||||
|
|
||||||
o(remove.callCount).equals(1)
|
o(remove.callCount).equals(1)
|
||||||
o(remove.this).equals(vnode.state)
|
o(remove.this).equals(vnode.state)
|
||||||
o(remove.args[0]).equals(vnode)
|
o(remove.args[0]).equals(vnode)
|
||||||
|
|
@ -60,10 +60,10 @@ o.spec("onremove", function() {
|
||||||
o("calls onremove when removing fragment", function() {
|
o("calls onremove when removing fragment", function() {
|
||||||
var remove = o.spy()
|
var remove = o.spy()
|
||||||
var vnode = {tag: "[", attrs: {onremove: remove}, children: [], state: {}}
|
var vnode = {tag: "[", attrs: {onremove: remove}, children: [], state: {}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [])
|
render(root, [])
|
||||||
|
|
||||||
o(remove.callCount).equals(1)
|
o(remove.callCount).equals(1)
|
||||||
o(remove.this).equals(vnode.state)
|
o(remove.this).equals(vnode.state)
|
||||||
o(remove.args[0]).equals(vnode)
|
o(remove.args[0]).equals(vnode)
|
||||||
|
|
@ -71,10 +71,10 @@ o.spec("onremove", function() {
|
||||||
o("calls onremove when removing html", function() {
|
o("calls onremove when removing html", function() {
|
||||||
var remove = o.spy()
|
var remove = o.spy()
|
||||||
var vnode = {tag: "<", attrs: {onremove: remove}, children: "a", state: {}}
|
var vnode = {tag: "<", attrs: {onremove: remove}, children: "a", state: {}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [])
|
render(root, [])
|
||||||
|
|
||||||
o(remove.callCount).equals(1)
|
o(remove.callCount).equals(1)
|
||||||
o(remove.this).equals(vnode.state)
|
o(remove.this).equals(vnode.state)
|
||||||
o(remove.args[0]).equals(vnode)
|
o(remove.args[0]).equals(vnode)
|
||||||
|
|
@ -82,9 +82,9 @@ o.spec("onremove", function() {
|
||||||
o("does not set onremove as an event handler", function() {
|
o("does not set onremove as an event handler", function() {
|
||||||
var remove = o.spy()
|
var remove = o.spy()
|
||||||
var vnode = {tag: "div", attrs: {onremove: remove}, children: []}
|
var vnode = {tag: "div", attrs: {onremove: remove}, children: []}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(vnode.dom.onremove).equals(undefined)
|
o(vnode.dom.onremove).equals(undefined)
|
||||||
o(vnode.dom.attributes["onremove"]).equals(undefined)
|
o(vnode.dom.attributes["onremove"]).equals(undefined)
|
||||||
})
|
})
|
||||||
|
|
@ -93,22 +93,22 @@ o.spec("onremove", function() {
|
||||||
var vnodes = [{tag: "div", key: 1}]
|
var vnodes = [{tag: "div", key: 1}]
|
||||||
var temp = [{tag: "div", key: 2, attrs: {onremove: remove}}]
|
var temp = [{tag: "div", key: 2, attrs: {onremove: remove}}]
|
||||||
var updated = [{tag: "div", key: 1}]
|
var updated = [{tag: "div", key: 1}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, temp)
|
render(root, temp)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(remove.callCount).equals(1)
|
o(remove.callCount).equals(1)
|
||||||
})
|
})
|
||||||
o("does not recycle when there's an onremove", function() {
|
o("does not recycle when there's an onremove", function() {
|
||||||
var remove = o.spy()
|
var remove = o.spy()
|
||||||
var vnode = {tag: "div", key: 1, attrs: {onremove: remove}}
|
var vnode = {tag: "div", key: 1, attrs: {onremove: remove}}
|
||||||
var updated = {tag: "div", key: 1, attrs: {onremove: remove}}
|
var updated = {tag: "div", key: 1, attrs: {onremove: remove}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [])
|
render(root, [])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(vnode.dom).notEquals(updated.dom)
|
o(vnode.dom).notEquals(updated.dom)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,10 @@ o.spec("onupdate", function() {
|
||||||
var update = o.spy()
|
var update = o.spy()
|
||||||
var vnode = {tag: "div", attrs: {onupdate: create}, state: {}}
|
var vnode = {tag: "div", attrs: {onupdate: create}, state: {}}
|
||||||
var updated = {tag: "div", attrs: {onupdate: update}, state: {}}
|
var updated = {tag: "div", attrs: {onupdate: update}, state: {}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(create.callCount).equals(0)
|
o(create.callCount).equals(0)
|
||||||
o(update.callCount).equals(1)
|
o(update.callCount).equals(1)
|
||||||
o(update.this).equals(vnode.state)
|
o(update.this).equals(vnode.state)
|
||||||
|
|
@ -29,10 +29,10 @@ o.spec("onupdate", function() {
|
||||||
o("does not call onupdate when removing element", function() {
|
o("does not call onupdate when removing element", function() {
|
||||||
var create = o.spy()
|
var create = o.spy()
|
||||||
var vnode = {tag: "div", attrs: {onupdate: create}}
|
var vnode = {tag: "div", attrs: {onupdate: create}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [])
|
render(root, [])
|
||||||
|
|
||||||
o(create.callCount).equals(0)
|
o(create.callCount).equals(0)
|
||||||
})
|
})
|
||||||
o("does not call onupdate when replacing keyed element", function() {
|
o("does not call onupdate when replacing keyed element", function() {
|
||||||
|
|
@ -42,7 +42,7 @@ o.spec("onupdate", function() {
|
||||||
var updated = {tag: "a", key: 1, attrs: {onupdate: update}}
|
var updated = {tag: "a", key: 1, attrs: {onupdate: update}}
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(create.callCount).equals(0)
|
o(create.callCount).equals(0)
|
||||||
o(update.callCount).equals(0)
|
o(update.callCount).equals(0)
|
||||||
})
|
})
|
||||||
|
|
@ -50,11 +50,11 @@ o.spec("onupdate", function() {
|
||||||
var update = o.spy()
|
var update = o.spy()
|
||||||
var vnode = {tag: "div", key: 1, attrs: {onupdate: update}}
|
var vnode = {tag: "div", key: 1, attrs: {onupdate: update}}
|
||||||
var updated = {tag: "div", key: 1, attrs: {onupdate: update}}
|
var updated = {tag: "div", key: 1, attrs: {onupdate: update}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [])
|
render(root, [])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(vnode.dom).notEquals(updated.dom)
|
o(vnode.dom).notEquals(updated.dom)
|
||||||
})
|
})
|
||||||
o("does not call old onupdate when removing the onupdate property in new vnode", function() {
|
o("does not call old onupdate when removing the onupdate property in new vnode", function() {
|
||||||
|
|
@ -62,10 +62,10 @@ o.spec("onupdate", function() {
|
||||||
var update = o.spy()
|
var update = o.spy()
|
||||||
var vnode = {tag: "a", attrs: {onupdate: create}}
|
var vnode = {tag: "a", attrs: {onupdate: create}}
|
||||||
var updated = {tag: "a"}
|
var updated = {tag: "a"}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(create.callCount).equals(0)
|
o(create.callCount).equals(0)
|
||||||
})
|
})
|
||||||
o("calls onupdate when noop", function() {
|
o("calls onupdate when noop", function() {
|
||||||
|
|
@ -73,10 +73,10 @@ o.spec("onupdate", function() {
|
||||||
var update = o.spy()
|
var update = o.spy()
|
||||||
var vnode = {tag: "div", attrs: {onupdate: create}, state: {}}
|
var vnode = {tag: "div", attrs: {onupdate: create}, state: {}}
|
||||||
var updated = {tag: "div", attrs: {onupdate: update}, state: {}}
|
var updated = {tag: "div", attrs: {onupdate: update}, state: {}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(create.callCount).equals(0)
|
o(create.callCount).equals(0)
|
||||||
o(update.callCount).equals(1)
|
o(update.callCount).equals(1)
|
||||||
o(update.this).equals(vnode.state)
|
o(update.this).equals(vnode.state)
|
||||||
|
|
@ -87,10 +87,10 @@ o.spec("onupdate", function() {
|
||||||
var update = o.spy()
|
var update = o.spy()
|
||||||
var vnode = {tag: "div", attrs: {onupdate: create}, state: {}}
|
var vnode = {tag: "div", attrs: {onupdate: create}, state: {}}
|
||||||
var updated = {tag: "div", attrs: {onupdate: update, id: "a"}, state: {}}
|
var updated = {tag: "div", attrs: {onupdate: update, id: "a"}, state: {}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(create.callCount).equals(0)
|
o(create.callCount).equals(0)
|
||||||
o(update.callCount).equals(1)
|
o(update.callCount).equals(1)
|
||||||
o(update.this).equals(vnode.state)
|
o(update.this).equals(vnode.state)
|
||||||
|
|
@ -101,10 +101,10 @@ o.spec("onupdate", function() {
|
||||||
var update = o.spy()
|
var update = o.spy()
|
||||||
var vnode = {tag: "div", attrs: {onupdate: create}, children: [{tag: "a"}], state: {}}
|
var vnode = {tag: "div", attrs: {onupdate: create}, children: [{tag: "a"}], state: {}}
|
||||||
var updated = {tag: "div", attrs: {onupdate: update}, children: [{tag: "b"}], state: {}}
|
var updated = {tag: "div", attrs: {onupdate: update}, children: [{tag: "b"}], state: {}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(create.callCount).equals(0)
|
o(create.callCount).equals(0)
|
||||||
o(update.callCount).equals(1)
|
o(update.callCount).equals(1)
|
||||||
o(update.this).equals(vnode.state)
|
o(update.this).equals(vnode.state)
|
||||||
|
|
@ -115,10 +115,10 @@ o.spec("onupdate", function() {
|
||||||
var update = o.spy()
|
var update = o.spy()
|
||||||
var vnode = {tag: "#", attrs: {onupdate: create}, children: "a", state: {}}
|
var vnode = {tag: "#", attrs: {onupdate: create}, children: "a", state: {}}
|
||||||
var updated = {tag: "#", attrs: {onupdate: update}, children: "a", state: {}}
|
var updated = {tag: "#", attrs: {onupdate: update}, children: "a", state: {}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(create.callCount).equals(0)
|
o(create.callCount).equals(0)
|
||||||
o(update.callCount).equals(1)
|
o(update.callCount).equals(1)
|
||||||
o(update.this).equals(vnode.state)
|
o(update.this).equals(vnode.state)
|
||||||
|
|
@ -129,10 +129,10 @@ o.spec("onupdate", function() {
|
||||||
var update = o.spy()
|
var update = o.spy()
|
||||||
var vnode = {tag: "[", attrs: {onupdate: create}, children: [], state: {}}
|
var vnode = {tag: "[", attrs: {onupdate: create}, children: [], state: {}}
|
||||||
var updated = {tag: "[", attrs: {onupdate: update}, children: [], state: {}}
|
var updated = {tag: "[", attrs: {onupdate: update}, children: [], state: {}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(create.callCount).equals(0)
|
o(create.callCount).equals(0)
|
||||||
o(update.callCount).equals(1)
|
o(update.callCount).equals(1)
|
||||||
o(update.this).equals(vnode.state)
|
o(update.this).equals(vnode.state)
|
||||||
|
|
@ -143,10 +143,10 @@ o.spec("onupdate", function() {
|
||||||
var update = o.spy()
|
var update = o.spy()
|
||||||
var vnode = {tag: "<", attrs: {onupdate: create}, children: "a", state: {}}
|
var vnode = {tag: "<", attrs: {onupdate: create}, children: "a", state: {}}
|
||||||
var updated = {tag: "<", attrs: {onupdate: update}, children: "a", state: {}}
|
var updated = {tag: "<", attrs: {onupdate: update}, children: "a", state: {}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(create.callCount).equals(0)
|
o(create.callCount).equals(0)
|
||||||
o(update.callCount).equals(1)
|
o(update.callCount).equals(1)
|
||||||
o(update.this).equals(vnode.state)
|
o(update.this).equals(vnode.state)
|
||||||
|
|
@ -164,13 +164,13 @@ o.spec("onupdate", function() {
|
||||||
{tag: "b", attrs: {id: "33"}}
|
{tag: "b", attrs: {id: "33"}}
|
||||||
]}
|
]}
|
||||||
]}
|
]}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
function update(vnode) {
|
function update(vnode) {
|
||||||
called = true
|
called = true
|
||||||
|
|
||||||
o(vnode.dom.parentNode.attributes["id"].nodeValue).equals("11")
|
o(vnode.dom.parentNode.attributes["id"].nodeValue).equals("11")
|
||||||
o(vnode.dom.attributes["id"].nodeValue).equals("22")
|
o(vnode.dom.attributes["id"].nodeValue).equals("22")
|
||||||
o(vnode.dom.childNodes[0].attributes["id"].nodeValue).equals("33")
|
o(vnode.dom.childNodes[0].attributes["id"].nodeValue).equals("33")
|
||||||
|
|
@ -180,10 +180,10 @@ o.spec("onupdate", function() {
|
||||||
o("does not set onupdate as an event handler", function() {
|
o("does not set onupdate as an event handler", function() {
|
||||||
var update = o.spy()
|
var update = o.spy()
|
||||||
var vnode = {tag: "div", attrs: {onupdate: update}, children: []}
|
var vnode = {tag: "div", attrs: {onupdate: update}, children: []}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
o(vnode.dom.onupdate).equals(undefined)
|
o(vnode.dom.onupdate).equals(undefined)
|
||||||
o(vnode.dom.attributes["onupdate"]).equals(undefined)
|
o(vnode.dom.attributes["onupdate"]).equals(undefined)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -14,27 +14,27 @@ o.spec("textContent", function() {
|
||||||
|
|
||||||
o("ignores null", function() {
|
o("ignores null", function() {
|
||||||
var vnodes = [{tag: "a", text: null}]
|
var vnodes = [{tag: "a", text: null}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
o(vnodes[0].dom.childNodes.length).equals(0)
|
o(vnodes[0].dom.childNodes.length).equals(0)
|
||||||
o(vnodes[0].dom).equals(root.childNodes[0])
|
o(vnodes[0].dom).equals(root.childNodes[0])
|
||||||
})
|
})
|
||||||
o("ignores undefined", function() {
|
o("ignores undefined", function() {
|
||||||
var vnodes = [{tag: "a", text: undefined}]
|
var vnodes = [{tag: "a", text: undefined}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
o(vnodes[0].dom.childNodes.length).equals(0)
|
o(vnodes[0].dom.childNodes.length).equals(0)
|
||||||
o(vnodes[0].dom).equals(root.childNodes[0])
|
o(vnodes[0].dom).equals(root.childNodes[0])
|
||||||
})
|
})
|
||||||
o("creates string", function() {
|
o("creates string", function() {
|
||||||
var vnodes = [{tag: "a", text: "a"}]
|
var vnodes = [{tag: "a", text: "a"}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
o(vnodes[0].dom.childNodes.length).equals(1)
|
o(vnodes[0].dom.childNodes.length).equals(1)
|
||||||
o(vnodes[0].dom.childNodes[0].nodeValue).equals("a")
|
o(vnodes[0].dom.childNodes[0].nodeValue).equals("a")
|
||||||
|
|
@ -42,9 +42,9 @@ o.spec("textContent", function() {
|
||||||
})
|
})
|
||||||
o("creates falsy string", function() {
|
o("creates falsy string", function() {
|
||||||
var vnodes = [{tag: "a", text: ""}]
|
var vnodes = [{tag: "a", text: ""}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
o(vnodes[0].dom.childNodes.length).equals(1)
|
o(vnodes[0].dom.childNodes.length).equals(1)
|
||||||
o(vnodes[0].dom.childNodes[0].nodeValue).equals("")
|
o(vnodes[0].dom.childNodes[0].nodeValue).equals("")
|
||||||
|
|
@ -52,9 +52,9 @@ o.spec("textContent", function() {
|
||||||
})
|
})
|
||||||
o("creates number", function() {
|
o("creates number", function() {
|
||||||
var vnodes = [{tag: "a", text: 1}]
|
var vnodes = [{tag: "a", text: 1}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
o(vnodes[0].dom.childNodes.length).equals(1)
|
o(vnodes[0].dom.childNodes.length).equals(1)
|
||||||
o(vnodes[0].dom.childNodes[0].nodeValue).equals("1")
|
o(vnodes[0].dom.childNodes[0].nodeValue).equals("1")
|
||||||
|
|
@ -62,9 +62,9 @@ o.spec("textContent", function() {
|
||||||
})
|
})
|
||||||
o("creates falsy number", function() {
|
o("creates falsy number", function() {
|
||||||
var vnodes = [{tag: "a", text: 0}]
|
var vnodes = [{tag: "a", text: 0}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
o(vnodes[0].dom.childNodes.length).equals(1)
|
o(vnodes[0].dom.childNodes.length).equals(1)
|
||||||
o(vnodes[0].dom.childNodes[0].nodeValue).equals("0")
|
o(vnodes[0].dom.childNodes[0].nodeValue).equals("0")
|
||||||
|
|
@ -72,9 +72,9 @@ o.spec("textContent", function() {
|
||||||
})
|
})
|
||||||
o("creates boolean", function() {
|
o("creates boolean", function() {
|
||||||
var vnodes = [{tag: "a", text: true}]
|
var vnodes = [{tag: "a", text: true}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
o(vnodes[0].dom.childNodes.length).equals(1)
|
o(vnodes[0].dom.childNodes.length).equals(1)
|
||||||
o(vnodes[0].dom.childNodes[0].nodeValue).equals("true")
|
o(vnodes[0].dom.childNodes[0].nodeValue).equals("true")
|
||||||
|
|
@ -82,9 +82,9 @@ o.spec("textContent", function() {
|
||||||
})
|
})
|
||||||
o("creates falsy boolean", function() {
|
o("creates falsy boolean", function() {
|
||||||
var vnodes = [{tag: "a", text: false}]
|
var vnodes = [{tag: "a", text: false}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
o(vnodes[0].dom.childNodes.length).equals(1)
|
o(vnodes[0].dom.childNodes.length).equals(1)
|
||||||
o(vnodes[0].dom.childNodes[0].nodeValue).equals("false")
|
o(vnodes[0].dom.childNodes[0].nodeValue).equals("false")
|
||||||
|
|
@ -93,10 +93,10 @@ o.spec("textContent", function() {
|
||||||
o("updates to string", function() {
|
o("updates to string", function() {
|
||||||
var vnodes = [{tag: "a", text: "a"}]
|
var vnodes = [{tag: "a", text: "a"}]
|
||||||
var updated = [{tag: "a", text: "b"}]
|
var updated = [{tag: "a", text: "b"}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
o(vnodes[0].dom.childNodes.length).equals(1)
|
o(vnodes[0].dom.childNodes.length).equals(1)
|
||||||
o(vnodes[0].dom.childNodes[0].nodeValue).equals("b")
|
o(vnodes[0].dom.childNodes[0].nodeValue).equals("b")
|
||||||
|
|
@ -105,10 +105,10 @@ o.spec("textContent", function() {
|
||||||
o("updates to falsy string", function() {
|
o("updates to falsy string", function() {
|
||||||
var vnodes = [{tag: "a", text: "a"}]
|
var vnodes = [{tag: "a", text: "a"}]
|
||||||
var updated = [{tag: "a", text: ""}]
|
var updated = [{tag: "a", text: ""}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
o(vnodes[0].dom.childNodes.length).equals(1)
|
o(vnodes[0].dom.childNodes.length).equals(1)
|
||||||
o(vnodes[0].dom.childNodes[0].nodeValue).equals("")
|
o(vnodes[0].dom.childNodes[0].nodeValue).equals("")
|
||||||
|
|
@ -117,10 +117,10 @@ o.spec("textContent", function() {
|
||||||
o("updates to number", function() {
|
o("updates to number", function() {
|
||||||
var vnodes = [{tag: "a", text: "a"}]
|
var vnodes = [{tag: "a", text: "a"}]
|
||||||
var updated = [{tag: "a", text: 1}]
|
var updated = [{tag: "a", text: 1}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
o(vnodes[0].dom.childNodes.length).equals(1)
|
o(vnodes[0].dom.childNodes.length).equals(1)
|
||||||
o(vnodes[0].dom.childNodes[0].nodeValue).equals("1")
|
o(vnodes[0].dom.childNodes[0].nodeValue).equals("1")
|
||||||
|
|
@ -129,10 +129,10 @@ o.spec("textContent", function() {
|
||||||
o("updates to falsy number", function() {
|
o("updates to falsy number", function() {
|
||||||
var vnodes = [{tag: "a", text: "a"}]
|
var vnodes = [{tag: "a", text: "a"}]
|
||||||
var updated = [{tag: "a", text: 0}]
|
var updated = [{tag: "a", text: 0}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
o(vnodes[0].dom.childNodes.length).equals(1)
|
o(vnodes[0].dom.childNodes.length).equals(1)
|
||||||
o(vnodes[0].dom.childNodes[0].nodeValue).equals("0")
|
o(vnodes[0].dom.childNodes[0].nodeValue).equals("0")
|
||||||
|
|
@ -141,10 +141,10 @@ o.spec("textContent", function() {
|
||||||
o("updates to boolean", function() {
|
o("updates to boolean", function() {
|
||||||
var vnodes = [{tag: "a", text: "a"}]
|
var vnodes = [{tag: "a", text: "a"}]
|
||||||
var updated = [{tag: "a", text: true}]
|
var updated = [{tag: "a", text: true}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
o(vnodes[0].dom.childNodes.length).equals(1)
|
o(vnodes[0].dom.childNodes.length).equals(1)
|
||||||
o(vnodes[0].dom.childNodes[0].nodeValue).equals("true")
|
o(vnodes[0].dom.childNodes[0].nodeValue).equals("true")
|
||||||
|
|
@ -153,10 +153,10 @@ o.spec("textContent", function() {
|
||||||
o("updates to falsy boolean", function() {
|
o("updates to falsy boolean", function() {
|
||||||
var vnodes = [{tag: "a", text: "a"}]
|
var vnodes = [{tag: "a", text: "a"}]
|
||||||
var updated = [{tag: "a", text: false}]
|
var updated = [{tag: "a", text: false}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
o(vnodes[0].dom.childNodes.length).equals(1)
|
o(vnodes[0].dom.childNodes.length).equals(1)
|
||||||
o(vnodes[0].dom.childNodes[0].nodeValue).equals("false")
|
o(vnodes[0].dom.childNodes[0].nodeValue).equals("false")
|
||||||
|
|
@ -165,10 +165,10 @@ o.spec("textContent", function() {
|
||||||
o("updates with typecasting", function() {
|
o("updates with typecasting", function() {
|
||||||
var vnodes = [{tag: "a", text: "1"}]
|
var vnodes = [{tag: "a", text: "1"}]
|
||||||
var updated = [{tag: "a", text: 1}]
|
var updated = [{tag: "a", text: 1}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
o(vnodes[0].dom.childNodes.length).equals(1)
|
o(vnodes[0].dom.childNodes.length).equals(1)
|
||||||
o(vnodes[0].dom.childNodes[0].nodeValue).equals("1")
|
o(vnodes[0].dom.childNodes[0].nodeValue).equals("1")
|
||||||
|
|
@ -177,10 +177,10 @@ o.spec("textContent", function() {
|
||||||
o("updates from without text to with text", function() {
|
o("updates from without text to with text", function() {
|
||||||
var vnodes = [{tag: "a"}]
|
var vnodes = [{tag: "a"}]
|
||||||
var updated = [{tag: "a", text: "b"}]
|
var updated = [{tag: "a", text: "b"}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
o(vnodes[0].dom.childNodes.length).equals(1)
|
o(vnodes[0].dom.childNodes.length).equals(1)
|
||||||
o(vnodes[0].dom.childNodes[0].nodeValue).equals("b")
|
o(vnodes[0].dom.childNodes[0].nodeValue).equals("b")
|
||||||
|
|
@ -189,12 +189,12 @@ o.spec("textContent", function() {
|
||||||
o("updates from with text to without text", function() {
|
o("updates from with text to without text", function() {
|
||||||
var vnodes = [{tag: "a", text: "a"}]
|
var vnodes = [{tag: "a", text: "a"}]
|
||||||
var updated = [{tag: "a"}]
|
var updated = [{tag: "a"}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
o(vnodes[0].dom.childNodes.length).equals(0)
|
o(vnodes[0].dom.childNodes.length).equals(0)
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,14 @@ var trust = require("../../render/trust")
|
||||||
o.spec("trust", function() {
|
o.spec("trust", function() {
|
||||||
o("works with html", function() {
|
o("works with html", function() {
|
||||||
var vnode = trust("<a></a>")
|
var vnode = trust("<a></a>")
|
||||||
|
|
||||||
o(vnode.tag).equals("<")
|
o(vnode.tag).equals("<")
|
||||||
o(vnode.children).equals("<a></a>")
|
o(vnode.children).equals("<a></a>")
|
||||||
})
|
})
|
||||||
o("works with text", function() {
|
o("works with text", function() {
|
||||||
var vnode = trust("abc")
|
var vnode = trust("abc")
|
||||||
|
|
||||||
o(vnode.tag).equals("<")
|
o(vnode.tag).equals("<")
|
||||||
o(vnode.children).equals("abc")
|
o(vnode.children).equals("abc")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,10 @@ o.spec("updateElement", function() {
|
||||||
o("updates attr", function() {
|
o("updates attr", function() {
|
||||||
var vnode = {tag: "a", attrs: {id: "b"}}
|
var vnode = {tag: "a", attrs: {id: "b"}}
|
||||||
var updated = {tag: "a", attrs: {id: "c"}}
|
var updated = {tag: "a", attrs: {id: "c"}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(updated.dom).equals(vnode.dom)
|
o(updated.dom).equals(vnode.dom)
|
||||||
o(updated.dom).equals(root.firstChild)
|
o(updated.dom).equals(root.firstChild)
|
||||||
o(updated.dom.attributes["id"].nodeValue).equals("c")
|
o(updated.dom.attributes["id"].nodeValue).equals("c")
|
||||||
|
|
@ -26,10 +26,10 @@ o.spec("updateElement", function() {
|
||||||
o("adds attr", function() {
|
o("adds attr", function() {
|
||||||
var vnode = {tag: "a", attrs: {id: "b"}}
|
var vnode = {tag: "a", attrs: {id: "b"}}
|
||||||
var updated = {tag: "a", attrs: {id: "c", title: "d"}}
|
var updated = {tag: "a", attrs: {id: "c", title: "d"}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(updated.dom).equals(vnode.dom)
|
o(updated.dom).equals(vnode.dom)
|
||||||
o(updated.dom).equals(root.firstChild)
|
o(updated.dom).equals(root.firstChild)
|
||||||
o(updated.dom.attributes["title"].nodeValue).equals("d")
|
o(updated.dom.attributes["title"].nodeValue).equals("d")
|
||||||
|
|
@ -37,10 +37,10 @@ o.spec("updateElement", function() {
|
||||||
o("adds attr from empty attrs", function() {
|
o("adds attr from empty attrs", function() {
|
||||||
var vnode = {tag: "a"}
|
var vnode = {tag: "a"}
|
||||||
var updated = {tag: "a", attrs: {title: "d"}}
|
var updated = {tag: "a", attrs: {title: "d"}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(updated.dom).equals(vnode.dom)
|
o(updated.dom).equals(vnode.dom)
|
||||||
o(updated.dom).equals(root.firstChild)
|
o(updated.dom).equals(root.firstChild)
|
||||||
o(updated.dom.attributes["title"].nodeValue).equals("d")
|
o(updated.dom.attributes["title"].nodeValue).equals("d")
|
||||||
|
|
@ -48,10 +48,10 @@ o.spec("updateElement", function() {
|
||||||
o("removes attr", function() {
|
o("removes attr", function() {
|
||||||
var vnode = {tag: "a", attrs: {id: "b", title: "d"}}
|
var vnode = {tag: "a", attrs: {id: "b", title: "d"}}
|
||||||
var updated = {tag: "a", attrs: {id: "c"}}
|
var updated = {tag: "a", attrs: {id: "c"}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(updated.dom).equals(vnode.dom)
|
o(updated.dom).equals(vnode.dom)
|
||||||
o(updated.dom).equals(root.firstChild)
|
o(updated.dom).equals(root.firstChild)
|
||||||
o("title" in updated.dom.attributes).equals(false)
|
o("title" in updated.dom.attributes).equals(false)
|
||||||
|
|
@ -59,145 +59,145 @@ o.spec("updateElement", function() {
|
||||||
o("creates style object", function() {
|
o("creates style object", function() {
|
||||||
var vnode = {tag: "a", attrs: {}}
|
var vnode = {tag: "a", attrs: {}}
|
||||||
var updated = {tag: "a", attrs: {style: {backgroundColor: "green"}}}
|
var updated = {tag: "a", attrs: {style: {backgroundColor: "green"}}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(updated.dom.style.backgroundColor).equals("green")
|
o(updated.dom.style.backgroundColor).equals("green")
|
||||||
})
|
})
|
||||||
o("creates style string", function() {
|
o("creates style string", function() {
|
||||||
var vnode = {tag: "a", attrs: {}}
|
var vnode = {tag: "a", attrs: {}}
|
||||||
var updated = {tag: "a", attrs: {style: "background-color:green"}}
|
var updated = {tag: "a", attrs: {style: "background-color:green"}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(updated.dom.style.backgroundColor).equals("green")
|
o(updated.dom.style.backgroundColor).equals("green")
|
||||||
})
|
})
|
||||||
o("updates style from object to object", function() {
|
o("updates style from object to object", function() {
|
||||||
var vnode = {tag: "a", attrs: {style: {backgroundColor: "red"}}}
|
var vnode = {tag: "a", attrs: {style: {backgroundColor: "red"}}}
|
||||||
var updated = {tag: "a", attrs: {style: {backgroundColor: "green"}}}
|
var updated = {tag: "a", attrs: {style: {backgroundColor: "green"}}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(updated.dom.style.backgroundColor).equals("green")
|
o(updated.dom.style.backgroundColor).equals("green")
|
||||||
})
|
})
|
||||||
o("updates style from object to string", function() {
|
o("updates style from object to string", function() {
|
||||||
var vnode = {tag: "a", attrs: {style: {backgroundColor: "red"}}}
|
var vnode = {tag: "a", attrs: {style: {backgroundColor: "red"}}}
|
||||||
var updated = {tag: "a", attrs: {style: "background-color:green;"}}
|
var updated = {tag: "a", attrs: {style: "background-color:green;"}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(updated.dom.style.backgroundColor).equals("green")
|
o(updated.dom.style.backgroundColor).equals("green")
|
||||||
})
|
})
|
||||||
o("handles noop style change when style is string", function() {
|
o("handles noop style change when style is string", function() {
|
||||||
var vnode = {tag: "a", attrs: {style: "background-color:green;"}}
|
var vnode = {tag: "a", attrs: {style: "background-color:green;"}}
|
||||||
var updated = {tag: "a", attrs: {style: "background-color:green;"}}
|
var updated = {tag: "a", attrs: {style: "background-color:green;"}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(updated.dom.style.backgroundColor).equals("green")
|
o(updated.dom.style.backgroundColor).equals("green")
|
||||||
})
|
})
|
||||||
o("handles noop style change when style is object", function() {
|
o("handles noop style change when style is object", function() {
|
||||||
var vnode = {tag: "a", attrs: {style: {backgroundColor: "red"}}}
|
var vnode = {tag: "a", attrs: {style: {backgroundColor: "red"}}}
|
||||||
var updated = {tag: "a", attrs: {style: {backgroundColor: "red"}}}
|
var updated = {tag: "a", attrs: {style: {backgroundColor: "red"}}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(updated.dom.style.backgroundColor).equals("red")
|
o(updated.dom.style.backgroundColor).equals("red")
|
||||||
})
|
})
|
||||||
o("updates style from string to object", function() {
|
o("updates style from string to object", function() {
|
||||||
var vnode = {tag: "a", attrs: {style: "background-color:red;"}}
|
var vnode = {tag: "a", attrs: {style: "background-color:red;"}}
|
||||||
var updated = {tag: "a", attrs: {style: {backgroundColor: "green"}}}
|
var updated = {tag: "a", attrs: {style: {backgroundColor: "green"}}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(updated.dom.style.backgroundColor).equals("green")
|
o(updated.dom.style.backgroundColor).equals("green")
|
||||||
})
|
})
|
||||||
o("updates style from string to string", function() {
|
o("updates style from string to string", function() {
|
||||||
var vnode = {tag: "a", attrs: {style: "background-color:red;"}}
|
var vnode = {tag: "a", attrs: {style: "background-color:red;"}}
|
||||||
var updated = {tag: "a", attrs: {style: "background-color:green;"}}
|
var updated = {tag: "a", attrs: {style: "background-color:green;"}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(updated.dom.style.backgroundColor).equals("green")
|
o(updated.dom.style.backgroundColor).equals("green")
|
||||||
})
|
})
|
||||||
o("removes style from object to object", function() {
|
o("removes style from object to object", function() {
|
||||||
var vnode = {tag: "a", attrs: {style: {backgroundColor: "red", border: "1px solid red"}}}
|
var vnode = {tag: "a", attrs: {style: {backgroundColor: "red", border: "1px solid red"}}}
|
||||||
var updated = {tag: "a", attrs: {style: {backgroundColor: "red"}}}
|
var updated = {tag: "a", attrs: {style: {backgroundColor: "red"}}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(updated.dom.style.backgroundColor).equals("red")
|
o(updated.dom.style.backgroundColor).equals("red")
|
||||||
o(updated.dom.style.border).equals("")
|
o(updated.dom.style.border).equals("")
|
||||||
})
|
})
|
||||||
o("removes style from string to object", function() {
|
o("removes style from string to object", function() {
|
||||||
var vnode = {tag: "a", attrs: {style: "background-color:red;border:1px solid red"}}
|
var vnode = {tag: "a", attrs: {style: "background-color:red;border:1px solid red"}}
|
||||||
var updated = {tag: "a", attrs: {style: {backgroundColor: "red"}}}
|
var updated = {tag: "a", attrs: {style: {backgroundColor: "red"}}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(updated.dom.style.backgroundColor).equals("red")
|
o(updated.dom.style.backgroundColor).equals("red")
|
||||||
o(updated.dom.style.border).notEquals("1px solid red")
|
o(updated.dom.style.border).notEquals("1px solid red")
|
||||||
})
|
})
|
||||||
o("removes style from object to string", function() {
|
o("removes style from object to string", function() {
|
||||||
var vnode = {tag: "a", attrs: {style: {backgroundColor: "red", border: "1px solid red"}}}
|
var vnode = {tag: "a", attrs: {style: {backgroundColor: "red", border: "1px solid red"}}}
|
||||||
var updated = {tag: "a", attrs: {style: "background-color:red"}}
|
var updated = {tag: "a", attrs: {style: "background-color:red"}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(updated.dom.style.backgroundColor).equals("red")
|
o(updated.dom.style.backgroundColor).equals("red")
|
||||||
o(updated.dom.style.border).equals("")
|
o(updated.dom.style.border).equals("")
|
||||||
})
|
})
|
||||||
o("removes style from string to string", function() {
|
o("removes style from string to string", function() {
|
||||||
var vnode = {tag: "a", attrs: {style: "background-color:red;border:1px solid red"}}
|
var vnode = {tag: "a", attrs: {style: "background-color:red;border:1px solid red"}}
|
||||||
var updated = {tag: "a", attrs: {style: "background-color:red"}}
|
var updated = {tag: "a", attrs: {style: "background-color:red"}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(updated.dom.style.backgroundColor).equals("red")
|
o(updated.dom.style.backgroundColor).equals("red")
|
||||||
o(updated.dom.style.border).equals("")
|
o(updated.dom.style.border).equals("")
|
||||||
})
|
})
|
||||||
o("updates style when it's same object but mutated", function() {
|
o("updates style when it's same object but mutated", function() {
|
||||||
var style = {backgroundColor: "red", color: "gold"}
|
var style = {backgroundColor: "red", color: "gold"}
|
||||||
var vnode = {tag: "a", attrs: {style: style}}
|
var vnode = {tag: "a", attrs: {style: style}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
delete style.backgroundColor
|
delete style.backgroundColor
|
||||||
var updated = {tag: "a", attrs: {style: style}}
|
var updated = {tag: "a", attrs: {style: style}}
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(updated.dom.style.backgroundColor).equals("")
|
o(updated.dom.style.backgroundColor).equals("")
|
||||||
o(updated.dom.style.color).equals("gold")
|
o(updated.dom.style.color).equals("gold")
|
||||||
})
|
})
|
||||||
o("replaces el", function() {
|
o("replaces el", function() {
|
||||||
var vnode = {tag: "a"}
|
var vnode = {tag: "a"}
|
||||||
var updated = {tag: "b"}
|
var updated = {tag: "b"}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(updated.dom).equals(root.firstChild)
|
o(updated.dom).equals(root.firstChild)
|
||||||
o(updated.dom.nodeName).equals("B")
|
o(updated.dom.nodeName).equals("B")
|
||||||
})
|
})
|
||||||
o("updates svg class", function() {
|
o("updates svg class", function() {
|
||||||
var vnode = {tag: "svg", attrs: {className: "a"}}
|
var vnode = {tag: "svg", attrs: {className: "a"}}
|
||||||
var updated = {tag: "svg", attrs: {className: "b"}}
|
var updated = {tag: "svg", attrs: {className: "b"}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(updated.dom.attributes["class"].nodeValue).equals("b")
|
o(updated.dom.attributes["class"].nodeValue).equals("b")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -15,20 +15,20 @@ o.spec("updateFragment", function() {
|
||||||
o("updates fragment", function() {
|
o("updates fragment", function() {
|
||||||
var vnode = {tag: "[", children: [{tag: "a"}]}
|
var vnode = {tag: "[", children: [{tag: "a"}]}
|
||||||
var updated = {tag: "[", children: [{tag: "b"}]}
|
var updated = {tag: "[", children: [{tag: "b"}]}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(updated.dom).equals(root.firstChild)
|
o(updated.dom).equals(root.firstChild)
|
||||||
o(updated.dom.nodeName).equals("B")
|
o(updated.dom.nodeName).equals("B")
|
||||||
})
|
})
|
||||||
o("adds els", function() {
|
o("adds els", function() {
|
||||||
var vnode = {tag: "[", children: []}
|
var vnode = {tag: "[", children: []}
|
||||||
var updated = {tag: "[", children: [{tag: "a"}, {tag: "b"}]}
|
var updated = {tag: "[", children: [{tag: "a"}, {tag: "b"}]}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(updated.dom).equals(root.firstChild)
|
o(updated.dom).equals(root.firstChild)
|
||||||
o(updated.domSize).equals(2)
|
o(updated.domSize).equals(2)
|
||||||
o(root.childNodes.length).equals(2)
|
o(root.childNodes.length).equals(2)
|
||||||
|
|
@ -38,10 +38,10 @@ o.spec("updateFragment", function() {
|
||||||
o("removes els", function() {
|
o("removes els", function() {
|
||||||
var vnode = {tag: "[", children: [{tag: "a"}, {tag: "b"}]}
|
var vnode = {tag: "[", children: [{tag: "a"}, {tag: "b"}]}
|
||||||
var updated = {tag: "[", children: []}
|
var updated = {tag: "[", children: []}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(updated.dom).equals(null)
|
o(updated.dom).equals(null)
|
||||||
o(updated.domSize).equals(0)
|
o(updated.domSize).equals(0)
|
||||||
o(root.childNodes.length).equals(0)
|
o(root.childNodes.length).equals(0)
|
||||||
|
|
@ -49,20 +49,20 @@ o.spec("updateFragment", function() {
|
||||||
o("updates from childless fragment", function() {
|
o("updates from childless fragment", function() {
|
||||||
var vnode = {tag: "["}
|
var vnode = {tag: "["}
|
||||||
var updated = {tag: "[", children: [{tag: "a"}]}
|
var updated = {tag: "[", children: [{tag: "a"}]}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(updated.dom).equals(root.firstChild)
|
o(updated.dom).equals(root.firstChild)
|
||||||
o(updated.dom.nodeName).equals("A")
|
o(updated.dom.nodeName).equals("A")
|
||||||
})
|
})
|
||||||
o("updates to childless fragment", function() {
|
o("updates to childless fragment", function() {
|
||||||
var vnode = {tag: "[", children: [{tag: "a"}]}
|
var vnode = {tag: "[", children: [{tag: "a"}]}
|
||||||
var updated = {tag: "["}
|
var updated = {tag: "["}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(updated.dom).equals(null)
|
o(updated.dom).equals(null)
|
||||||
o(root.childNodes.length).equals(0)
|
o(root.childNodes.length).equals(0)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -15,20 +15,20 @@ o.spec("updateHTML", function() {
|
||||||
o("updates html", function() {
|
o("updates html", function() {
|
||||||
var vnode = {tag: "<", children: "a"}
|
var vnode = {tag: "<", children: "a"}
|
||||||
var updated = {tag: "<", children: "b"}
|
var updated = {tag: "<", children: "b"}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(updated.dom).equals(root.firstChild)
|
o(updated.dom).equals(root.firstChild)
|
||||||
o(updated.dom.nodeValue).equals("b")
|
o(updated.dom.nodeValue).equals("b")
|
||||||
})
|
})
|
||||||
o("adds html", function() {
|
o("adds html", function() {
|
||||||
var vnode = {tag: "<", children: ""}
|
var vnode = {tag: "<", children: ""}
|
||||||
var updated = {tag: "<", children: "<a></a><b></b>"}
|
var updated = {tag: "<", children: "<a></a><b></b>"}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(updated.domSize).equals(2)
|
o(updated.domSize).equals(2)
|
||||||
o(updated.dom).equals(root.firstChild)
|
o(updated.dom).equals(root.firstChild)
|
||||||
o(root.childNodes.length).equals(2)
|
o(root.childNodes.length).equals(2)
|
||||||
|
|
@ -38,10 +38,10 @@ o.spec("updateHTML", function() {
|
||||||
o("removes html", function() {
|
o("removes html", function() {
|
||||||
var vnode = {tag: "<", children: "<a></a><b></b>"}
|
var vnode = {tag: "<", children: "<a></a><b></b>"}
|
||||||
var updated = {tag: "<", children: ""}
|
var updated = {tag: "<", children: ""}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(updated.dom).equals(null)
|
o(updated.dom).equals(null)
|
||||||
o(updated.domSize).equals(0)
|
o(updated.domSize).equals(0)
|
||||||
o(root.childNodes.length).equals(0)
|
o(root.childNodes.length).equals(0)
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,10 @@ o.spec("updateNodes", function() {
|
||||||
o("handles el noop", function() {
|
o("handles el noop", function() {
|
||||||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
||||||
var updated = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
var updated = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(2)
|
o(root.childNodes.length).equals(2)
|
||||||
o(updated[0].dom.nodeName).equals("A")
|
o(updated[0].dom.nodeName).equals("A")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -28,10 +28,10 @@ o.spec("updateNodes", function() {
|
||||||
o("handles el noop without key", function() {
|
o("handles el noop without key", function() {
|
||||||
var vnodes = [{tag: "a"}, {tag: "b"}]
|
var vnodes = [{tag: "a"}, {tag: "b"}]
|
||||||
var updated = [{tag: "a"}, {tag: "b"}]
|
var updated = [{tag: "a"}, {tag: "b"}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(2)
|
o(root.childNodes.length).equals(2)
|
||||||
o(updated[0].dom.nodeName).equals("A")
|
o(updated[0].dom.nodeName).equals("A")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -41,10 +41,10 @@ o.spec("updateNodes", function() {
|
||||||
o("handles text noop", function() {
|
o("handles text noop", function() {
|
||||||
var vnodes = [{tag: "#", children: "a"}]
|
var vnodes = [{tag: "#", children: "a"}]
|
||||||
var updated = [{tag: "#", children: "a"}]
|
var updated = [{tag: "#", children: "a"}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
o(updated[0].dom.nodeValue).equals("a")
|
o(updated[0].dom.nodeValue).equals("a")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -52,10 +52,10 @@ o.spec("updateNodes", function() {
|
||||||
o("handles text noop w/ type casting", function() {
|
o("handles text noop w/ type casting", function() {
|
||||||
var vnodes = [{tag: "#", children: 1}]
|
var vnodes = [{tag: "#", children: 1}]
|
||||||
var updated = [{tag: "#", children: "1"}]
|
var updated = [{tag: "#", children: "1"}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
o(updated[0].dom.nodeValue).equals("1")
|
o(updated[0].dom.nodeValue).equals("1")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -63,10 +63,10 @@ o.spec("updateNodes", function() {
|
||||||
o("handles falsy text noop w/ type casting", function() {
|
o("handles falsy text noop w/ type casting", function() {
|
||||||
var vnodes = [{tag: "#", children: 0}]
|
var vnodes = [{tag: "#", children: 0}]
|
||||||
var updated = [{tag: "#", children: "0"}]
|
var updated = [{tag: "#", children: "0"}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
o(updated[0].dom.nodeValue).equals("0")
|
o(updated[0].dom.nodeValue).equals("0")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -74,10 +74,10 @@ o.spec("updateNodes", function() {
|
||||||
o("handles html noop", function() {
|
o("handles html noop", function() {
|
||||||
var vnodes = [{tag: "<", children: "a"}]
|
var vnodes = [{tag: "<", children: "a"}]
|
||||||
var updated = [{tag: "<", children: "a"}]
|
var updated = [{tag: "<", children: "a"}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
o(updated[0].dom.nodeValue).equals("a")
|
o(updated[0].dom.nodeValue).equals("a")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -85,10 +85,10 @@ o.spec("updateNodes", function() {
|
||||||
o("handles fragment noop", function() {
|
o("handles fragment noop", function() {
|
||||||
var vnodes = [{tag: "[", children: [{tag: "a"}]}]
|
var vnodes = [{tag: "[", children: [{tag: "a"}]}]
|
||||||
var updated = [{tag: "[", children: [{tag: "a"}]}]
|
var updated = [{tag: "[", children: [{tag: "a"}]}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
o(updated[0].dom.nodeName).equals("A")
|
o(updated[0].dom.nodeName).equals("A")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -96,10 +96,10 @@ o.spec("updateNodes", function() {
|
||||||
o("handles fragment noop w/ text child", function() {
|
o("handles fragment noop w/ text child", function() {
|
||||||
var vnodes = [{tag: "[", children: [{tag: "#", children: "a"}]}]
|
var vnodes = [{tag: "[", children: [{tag: "#", children: "a"}]}]
|
||||||
var updated = [{tag: "[", children: [{tag: "#", children: "a"}]}]
|
var updated = [{tag: "[", children: [{tag: "#", children: "a"}]}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
o(updated[0].dom.nodeValue).equals("a")
|
o(updated[0].dom.nodeValue).equals("a")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -107,10 +107,10 @@ o.spec("updateNodes", function() {
|
||||||
o("reverses els w/ even count", function() {
|
o("reverses els w/ even count", function() {
|
||||||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}, {tag: "i", key: 3}, {tag: "s", key: 4}]
|
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}, {tag: "i", key: 3}, {tag: "s", key: 4}]
|
||||||
var updated = [{tag: "s", key: 4}, {tag: "i", key: 3}, {tag: "b", key: 2}, {tag: "a", key: 1}]
|
var updated = [{tag: "s", key: 4}, {tag: "i", key: 3}, {tag: "b", key: 2}, {tag: "a", key: 1}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(4)
|
o(root.childNodes.length).equals(4)
|
||||||
o(updated[0].dom.nodeName).equals("S")
|
o(updated[0].dom.nodeName).equals("S")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -124,10 +124,10 @@ o.spec("updateNodes", function() {
|
||||||
o("reverses els w/ odd count", function() {
|
o("reverses els w/ odd count", function() {
|
||||||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}, {tag: "i", key: 3}]
|
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}, {tag: "i", key: 3}]
|
||||||
var updated = [{tag: "i", key: 3}, {tag: "b", key: 2}, {tag: "a", key: 1}]
|
var updated = [{tag: "i", key: 3}, {tag: "b", key: 2}, {tag: "a", key: 1}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(3)
|
o(root.childNodes.length).equals(3)
|
||||||
o(updated[0].dom.nodeName).equals("I")
|
o(updated[0].dom.nodeName).equals("I")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -139,10 +139,10 @@ o.spec("updateNodes", function() {
|
||||||
o("creates el at start", function() {
|
o("creates el at start", function() {
|
||||||
var vnodes = [{tag: "a", key: 1}]
|
var vnodes = [{tag: "a", key: 1}]
|
||||||
var updated = [{tag: "b", key: 2}, {tag: "a", key: 1}]
|
var updated = [{tag: "b", key: 2}, {tag: "a", key: 1}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(2)
|
o(root.childNodes.length).equals(2)
|
||||||
o(updated[0].dom.nodeName).equals("B")
|
o(updated[0].dom.nodeName).equals("B")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -152,10 +152,10 @@ o.spec("updateNodes", function() {
|
||||||
o("creates el at end", function() {
|
o("creates el at end", function() {
|
||||||
var vnodes = [{tag: "a", key: 1}]
|
var vnodes = [{tag: "a", key: 1}]
|
||||||
var updated = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
var updated = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(2)
|
o(root.childNodes.length).equals(2)
|
||||||
o(updated[0].dom.nodeName).equals("A")
|
o(updated[0].dom.nodeName).equals("A")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -165,10 +165,10 @@ o.spec("updateNodes", function() {
|
||||||
o("creates el in middle", function() {
|
o("creates el in middle", function() {
|
||||||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
||||||
var updated = [{tag: "a", key: 1}, {tag: "i", key: 3}, {tag: "b", key: 2}]
|
var updated = [{tag: "a", key: 1}, {tag: "i", key: 3}, {tag: "b", key: 2}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(updated[0].dom.nodeName).equals("A")
|
o(updated[0].dom.nodeName).equals("A")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
o(updated[1].dom.nodeName).equals("I")
|
o(updated[1].dom.nodeName).equals("I")
|
||||||
|
|
@ -179,10 +179,10 @@ o.spec("updateNodes", function() {
|
||||||
o("creates el while reversing", function() {
|
o("creates el while reversing", function() {
|
||||||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
||||||
var updated = [{tag: "b", key: 2}, {tag: "i", key: 3}, {tag: "a", key: 1}]
|
var updated = [{tag: "b", key: 2}, {tag: "i", key: 3}, {tag: "a", key: 1}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(3)
|
o(root.childNodes.length).equals(3)
|
||||||
o(updated[0].dom.nodeName).equals("B")
|
o(updated[0].dom.nodeName).equals("B")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -194,10 +194,10 @@ o.spec("updateNodes", function() {
|
||||||
o("deletes el at start", function() {
|
o("deletes el at start", function() {
|
||||||
var vnodes = [{tag: "b", key: 2}, {tag: "a", key: 1}]
|
var vnodes = [{tag: "b", key: 2}, {tag: "a", key: 1}]
|
||||||
var updated = [{tag: "a", key: 1}]
|
var updated = [{tag: "a", key: 1}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
o(updated[0].dom.nodeName).equals("A")
|
o(updated[0].dom.nodeName).equals("A")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -205,10 +205,10 @@ o.spec("updateNodes", function() {
|
||||||
o("deletes el at end", function() {
|
o("deletes el at end", function() {
|
||||||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
||||||
var updated = [{tag: "a", key: 1}]
|
var updated = [{tag: "a", key: 1}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
o(updated[0].dom.nodeName).equals("A")
|
o(updated[0].dom.nodeName).equals("A")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -216,10 +216,10 @@ o.spec("updateNodes", function() {
|
||||||
o("deletes el at middle", function() {
|
o("deletes el at middle", function() {
|
||||||
var vnodes = [{tag: "a", key: 1}, {tag: "i", key: 3}, {tag: "b", key: 2}]
|
var vnodes = [{tag: "a", key: 1}, {tag: "i", key: 3}, {tag: "b", key: 2}]
|
||||||
var updated = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
var updated = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(2)
|
o(root.childNodes.length).equals(2)
|
||||||
o(updated[0].dom.nodeName).equals("A")
|
o(updated[0].dom.nodeName).equals("A")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -229,10 +229,10 @@ o.spec("updateNodes", function() {
|
||||||
o("deletes el while reversing", function() {
|
o("deletes el while reversing", function() {
|
||||||
var vnodes = [{tag: "a", key: 1}, {tag: "i", key: 3}, {tag: "b", key: 2}]
|
var vnodes = [{tag: "a", key: 1}, {tag: "i", key: 3}, {tag: "b", key: 2}]
|
||||||
var updated = [{tag: "b", key: 2}, {tag: "a", key: 1}]
|
var updated = [{tag: "b", key: 2}, {tag: "a", key: 1}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(2)
|
o(root.childNodes.length).equals(2)
|
||||||
o(updated[0].dom.nodeName).equals("B")
|
o(updated[0].dom.nodeName).equals("B")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -242,10 +242,10 @@ o.spec("updateNodes", function() {
|
||||||
o("creates, deletes, reverses els at same time", function() {
|
o("creates, deletes, reverses els at same time", function() {
|
||||||
var vnodes = [{tag: "a", key: 1}, {tag: "i", key: 3}, {tag: "b", key: 2}]
|
var vnodes = [{tag: "a", key: 1}, {tag: "i", key: 3}, {tag: "b", key: 2}]
|
||||||
var updated = [{tag: "b", key: 2}, {tag: "a", key: 1}, {tag: "s", key: 4}]
|
var updated = [{tag: "b", key: 2}, {tag: "a", key: 1}, {tag: "s", key: 4}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(3)
|
o(root.childNodes.length).equals(3)
|
||||||
o(updated[0].dom.nodeName).equals("B")
|
o(updated[0].dom.nodeName).equals("B")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -257,10 +257,10 @@ o.spec("updateNodes", function() {
|
||||||
o("adds to empty array followed by el", function() {
|
o("adds to empty array followed by el", function() {
|
||||||
var vnodes = [{tag: "[", key: 1, children: []}, {tag: "b", key: 2}]
|
var vnodes = [{tag: "[", key: 1, children: []}, {tag: "b", key: 2}]
|
||||||
var updated = [{tag: "[", key: 1, children: [{tag: "a"}]}, {tag: "b", key: 2}]
|
var updated = [{tag: "[", key: 1, children: [{tag: "a"}]}, {tag: "b", key: 2}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(2)
|
o(root.childNodes.length).equals(2)
|
||||||
o(updated[0].children[0].dom.nodeName).equals("A")
|
o(updated[0].children[0].dom.nodeName).equals("A")
|
||||||
o(updated[0].children[0].dom).equals(root.childNodes[0])
|
o(updated[0].children[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -270,10 +270,10 @@ o.spec("updateNodes", function() {
|
||||||
o("reverses followed by el", function() {
|
o("reverses followed by el", function() {
|
||||||
var vnodes = [{tag: "[", key: 1, children: [{tag: "a", key: 2}, {tag: "b", key: 3}]}, {tag: "i", key: 4}]
|
var vnodes = [{tag: "[", key: 1, children: [{tag: "a", key: 2}, {tag: "b", key: 3}]}, {tag: "i", key: 4}]
|
||||||
var updated = [{tag: "[", key: 1, children: [{tag: "b", key: 3}, {tag: "a", key: 2}]}, {tag: "i", key: 4}]
|
var updated = [{tag: "[", key: 1, children: [{tag: "b", key: 3}, {tag: "a", key: 2}]}, {tag: "i", key: 4}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(3)
|
o(root.childNodes.length).equals(3)
|
||||||
o(updated[0].children[0].dom.nodeName).equals("B")
|
o(updated[0].children[0].dom.nodeName).equals("B")
|
||||||
o(updated[0].children[0].dom).equals(root.childNodes[0])
|
o(updated[0].children[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -285,10 +285,10 @@ o.spec("updateNodes", function() {
|
||||||
o("updates empty array to html with same key", function() {
|
o("updates empty array to html with same key", function() {
|
||||||
var vnodes = [{tag: "[", key: 1, children: []}]
|
var vnodes = [{tag: "[", key: 1, children: []}]
|
||||||
var updated = [{tag: "<", key: 1, children: "<a></a><b></b>"}]
|
var updated = [{tag: "<", key: 1, children: "<a></a><b></b>"}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(2)
|
o(root.childNodes.length).equals(2)
|
||||||
o(updated[0].dom.nodeName).equals("A")
|
o(updated[0].dom.nodeName).equals("A")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -299,10 +299,10 @@ o.spec("updateNodes", function() {
|
||||||
o("updates empty html to array with same key", function() {
|
o("updates empty html to array with same key", function() {
|
||||||
var vnodes = [{tag: "<", key: 1, children: ""}]
|
var vnodes = [{tag: "<", key: 1, children: ""}]
|
||||||
var updated = [{tag: "[", key: 1, children: [{tag: "a"}, {tag: "b"}]}]
|
var updated = [{tag: "[", key: 1, children: [{tag: "a"}, {tag: "b"}]}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(2)
|
o(root.childNodes.length).equals(2)
|
||||||
o(updated[0].dom.nodeName).equals("A")
|
o(updated[0].dom.nodeName).equals("A")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -313,10 +313,10 @@ o.spec("updateNodes", function() {
|
||||||
o("updates empty array to html without key", function() {
|
o("updates empty array to html without key", function() {
|
||||||
var vnodes = [{tag: "[", children: []}]
|
var vnodes = [{tag: "[", children: []}]
|
||||||
var updated = [{tag: "<", children: "<a></a><b></b>"}]
|
var updated = [{tag: "<", children: "<a></a><b></b>"}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(2)
|
o(root.childNodes.length).equals(2)
|
||||||
o(updated[0].dom.nodeName).equals("A")
|
o(updated[0].dom.nodeName).equals("A")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -327,10 +327,10 @@ o.spec("updateNodes", function() {
|
||||||
o("updates empty html to array without key", function() {
|
o("updates empty html to array without key", function() {
|
||||||
var vnodes = [{tag: "<", children: ""}]
|
var vnodes = [{tag: "<", children: ""}]
|
||||||
var updated = [{tag: "[", children: [{tag: "a"}, {tag: "b"}]}]
|
var updated = [{tag: "[", children: [{tag: "a"}, {tag: "b"}]}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(2)
|
o(root.childNodes.length).equals(2)
|
||||||
o(updated[0].dom.nodeName).equals("A")
|
o(updated[0].dom.nodeName).equals("A")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -341,10 +341,10 @@ o.spec("updateNodes", function() {
|
||||||
o("updates array to html with same key", function() {
|
o("updates array to html with same key", function() {
|
||||||
var vnodes = [{tag: "[", key: 1, children: [{tag: "a"}, {tag: "b"}]}]
|
var vnodes = [{tag: "[", key: 1, children: [{tag: "a"}, {tag: "b"}]}]
|
||||||
var updated = [{tag: "<", key: 1, children: "<i></i><s></s>"}]
|
var updated = [{tag: "<", key: 1, children: "<i></i><s></s>"}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(2)
|
o(root.childNodes.length).equals(2)
|
||||||
o(updated[0].dom.nodeName).equals("I")
|
o(updated[0].dom.nodeName).equals("I")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -355,10 +355,10 @@ o.spec("updateNodes", function() {
|
||||||
o("updates html to array with same key", function() {
|
o("updates html to array with same key", function() {
|
||||||
var vnodes = [{tag: "<", key: 1, children: "<a></a><b></b>"}]
|
var vnodes = [{tag: "<", key: 1, children: "<a></a><b></b>"}]
|
||||||
var updated = [{tag: "[", key: 1, children: [{tag: "i"}, {tag: "s"}]}]
|
var updated = [{tag: "[", key: 1, children: [{tag: "i"}, {tag: "s"}]}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(2)
|
o(root.childNodes.length).equals(2)
|
||||||
o(updated[0].dom.nodeName).equals("I")
|
o(updated[0].dom.nodeName).equals("I")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -369,10 +369,10 @@ o.spec("updateNodes", function() {
|
||||||
o("updates array to html without key", function() {
|
o("updates array to html without key", function() {
|
||||||
var vnodes = [{tag: "[", children: [{tag: "a"}, {tag: "b"}]}]
|
var vnodes = [{tag: "[", children: [{tag: "a"}, {tag: "b"}]}]
|
||||||
var updated = [{tag: "<", children: "<i></i><s></s>"}]
|
var updated = [{tag: "<", children: "<i></i><s></s>"}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(2)
|
o(root.childNodes.length).equals(2)
|
||||||
o(updated[0].dom.nodeName).equals("I")
|
o(updated[0].dom.nodeName).equals("I")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -383,10 +383,10 @@ o.spec("updateNodes", function() {
|
||||||
o("updates html to array without key", function() {
|
o("updates html to array without key", function() {
|
||||||
var vnodes = [{tag: "<", children: "<a></a><b></b>"}]
|
var vnodes = [{tag: "<", children: "<a></a><b></b>"}]
|
||||||
var updated = [{tag: "[", children: [{tag: "i"}, {tag: "s"}]}]
|
var updated = [{tag: "[", children: [{tag: "i"}, {tag: "s"}]}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(2)
|
o(root.childNodes.length).equals(2)
|
||||||
o(updated[0].dom.nodeName).equals("I")
|
o(updated[0].dom.nodeName).equals("I")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -397,10 +397,10 @@ o.spec("updateNodes", function() {
|
||||||
o("updates empty array to html with same key followed by el", function() {
|
o("updates empty array to html with same key followed by el", function() {
|
||||||
var vnodes = [{tag: "[", key: 1, children: []}, {tag: "i", key: 2}]
|
var vnodes = [{tag: "[", key: 1, children: []}, {tag: "i", key: 2}]
|
||||||
var updated = [{tag: "<", key: 1, children: "<a></a><b></b>"}, {tag: "i", key: 2}]
|
var updated = [{tag: "<", key: 1, children: "<a></a><b></b>"}, {tag: "i", key: 2}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(3)
|
o(root.childNodes.length).equals(3)
|
||||||
o(updated[0].dom.nodeName).equals("A")
|
o(updated[0].dom.nodeName).equals("A")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -413,10 +413,10 @@ o.spec("updateNodes", function() {
|
||||||
o("updates empty html to array with same key followed by el", function() {
|
o("updates empty html to array with same key followed by el", function() {
|
||||||
var vnodes = [{tag: "[", key: 1, children: []}, {tag: "i", key: 2}]
|
var vnodes = [{tag: "[", key: 1, children: []}, {tag: "i", key: 2}]
|
||||||
var updated = [{tag: "<", key: 1, children: "<a></a><b></b>"}, {tag: "i", key: 2}]
|
var updated = [{tag: "<", key: 1, children: "<a></a><b></b>"}, {tag: "i", key: 2}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(3)
|
o(root.childNodes.length).equals(3)
|
||||||
o(updated[0].dom.nodeName).equals("A")
|
o(updated[0].dom.nodeName).equals("A")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -429,10 +429,10 @@ o.spec("updateNodes", function() {
|
||||||
o("populates array followed by null then el", function() {
|
o("populates array followed by null then el", function() {
|
||||||
var vnodes = [{tag: "[", key: 1, children: []}, null, {tag: "i", key: 2}]
|
var vnodes = [{tag: "[", key: 1, children: []}, null, {tag: "i", key: 2}]
|
||||||
var updated = [{tag: "[", key: 1, children: [{tag: "a"}, {tag: "b"}]}, null, {tag: "i", key: 2}]
|
var updated = [{tag: "[", key: 1, children: [{tag: "a"}, {tag: "b"}]}, null, {tag: "i", key: 2}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(3)
|
o(root.childNodes.length).equals(3)
|
||||||
o(updated[0].dom.nodeName).equals("A")
|
o(updated[0].dom.nodeName).equals("A")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -445,10 +445,10 @@ o.spec("updateNodes", function() {
|
||||||
o("populates childless array followed by el", function() {
|
o("populates childless array followed by el", function() {
|
||||||
var vnodes = [{tag: "[", key: 1}, {tag: "i", key: 2}]
|
var vnodes = [{tag: "[", key: 1}, {tag: "i", key: 2}]
|
||||||
var updated = [{tag: "[", key: 1, children: [{tag: "a"}, {tag: "b"}]}, {tag: "i", key: 2}]
|
var updated = [{tag: "[", key: 1, children: [{tag: "a"}, {tag: "b"}]}, {tag: "i", key: 2}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(3)
|
o(root.childNodes.length).equals(3)
|
||||||
o(updated[0].dom.nodeName).equals("A")
|
o(updated[0].dom.nodeName).equals("A")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -461,10 +461,10 @@ o.spec("updateNodes", function() {
|
||||||
o("populates childless array followed by null then el", function() {
|
o("populates childless array followed by null then el", function() {
|
||||||
var vnodes = [{tag: "[", key: 1}, null, {tag: "i", key: 2}]
|
var vnodes = [{tag: "[", key: 1}, null, {tag: "i", key: 2}]
|
||||||
var updated = [{tag: "[", key: 1, children: [{tag: "a"}, {tag: "b"}]}, null, {tag: "i", key: 2}]
|
var updated = [{tag: "[", key: 1, children: [{tag: "a"}, {tag: "b"}]}, null, {tag: "i", key: 2}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(3)
|
o(root.childNodes.length).equals(3)
|
||||||
o(updated[0].dom.nodeName).equals("A")
|
o(updated[0].dom.nodeName).equals("A")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -477,10 +477,10 @@ o.spec("updateNodes", function() {
|
||||||
o("moves from end to start", function() {
|
o("moves from end to start", function() {
|
||||||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}, {tag: "i", key: 3}, {tag: "s", key: 4}]
|
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}, {tag: "i", key: 3}, {tag: "s", key: 4}]
|
||||||
var updated = [{tag: "s", key: 4}, {tag: "a", key: 1}, {tag: "b", key: 2}, {tag: "i", key: 3}]
|
var updated = [{tag: "s", key: 4}, {tag: "a", key: 1}, {tag: "b", key: 2}, {tag: "i", key: 3}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(4)
|
o(root.childNodes.length).equals(4)
|
||||||
o(updated[0].dom.nodeName).equals("S")
|
o(updated[0].dom.nodeName).equals("S")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -494,10 +494,10 @@ o.spec("updateNodes", function() {
|
||||||
o("moves from start to end", function() {
|
o("moves from start to end", function() {
|
||||||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}, {tag: "i", key: 3}, {tag: "s", key: 4}]
|
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}, {tag: "i", key: 3}, {tag: "s", key: 4}]
|
||||||
var updated = [{tag: "b", key: 2}, {tag: "i", key: 3}, {tag: "s", key: 4}, {tag: "a", key: 1}]
|
var updated = [{tag: "b", key: 2}, {tag: "i", key: 3}, {tag: "s", key: 4}, {tag: "a", key: 1}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(4)
|
o(root.childNodes.length).equals(4)
|
||||||
o(updated[0].dom.nodeName).equals("B")
|
o(updated[0].dom.nodeName).equals("B")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -512,11 +512,11 @@ o.spec("updateNodes", function() {
|
||||||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}, {tag: "i", key: 3}, {tag: "s", key: 4}]
|
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}, {tag: "i", key: 3}, {tag: "s", key: 4}]
|
||||||
var temp = []
|
var temp = []
|
||||||
var updated = [{tag: "a", key: 1}, {tag: "b", key: 2}, {tag: "i", key: 3}, {tag: "s", key: 4}]
|
var updated = [{tag: "a", key: 1}, {tag: "b", key: 2}, {tag: "i", key: 3}, {tag: "s", key: 4}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, temp)
|
render(root, temp)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(4)
|
o(root.childNodes.length).equals(4)
|
||||||
o(updated[0].dom.nodeName).equals("A")
|
o(updated[0].dom.nodeName).equals("A")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -531,11 +531,11 @@ o.spec("updateNodes", function() {
|
||||||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}, {tag: "i", key: 3}, {tag: "s", key: 4}]
|
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}, {tag: "i", key: 3}, {tag: "s", key: 4}]
|
||||||
var temp = []
|
var temp = []
|
||||||
var updated = [{tag: "s", key: 4}, {tag: "i", key: 3}, {tag: "b", key: 2}, {tag: "a", key: 1}]
|
var updated = [{tag: "s", key: 4}, {tag: "i", key: 3}, {tag: "b", key: 2}, {tag: "a", key: 1}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, temp)
|
render(root, temp)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(4)
|
o(root.childNodes.length).equals(4)
|
||||||
o(updated[0].dom.nodeName).equals("S")
|
o(updated[0].dom.nodeName).equals("S")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -550,11 +550,11 @@ o.spec("updateNodes", function() {
|
||||||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
||||||
var temp = []
|
var temp = []
|
||||||
var updated = [{tag: "a", key: 1}]
|
var updated = [{tag: "a", key: 1}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, temp)
|
render(root, temp)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
o(updated[0].dom.nodeName).equals("A")
|
o(updated[0].dom.nodeName).equals("A")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -563,11 +563,11 @@ o.spec("updateNodes", function() {
|
||||||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
||||||
var temp = []
|
var temp = []
|
||||||
var updated = [{tag: "a", key: 1}, {tag: "b", key: 2}, {tag: "i", key: 3}]
|
var updated = [{tag: "a", key: 1}, {tag: "b", key: 2}, {tag: "i", key: 3}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, temp)
|
render(root, temp)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(3)
|
o(root.childNodes.length).equals(3)
|
||||||
o(updated[0].dom.nodeName).equals("A")
|
o(updated[0].dom.nodeName).equals("A")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -580,11 +580,11 @@ o.spec("updateNodes", function() {
|
||||||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
||||||
var temp = []
|
var temp = []
|
||||||
var updated = [{tag: "i", key: 3}, {tag: "s", key: 4}]
|
var updated = [{tag: "i", key: 3}, {tag: "s", key: 4}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, temp)
|
render(root, temp)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(2)
|
o(root.childNodes.length).equals(2)
|
||||||
o(updated[0].dom.nodeName).equals("I")
|
o(updated[0].dom.nodeName).equals("I")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -595,11 +595,11 @@ o.spec("updateNodes", function() {
|
||||||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
||||||
var temp = []
|
var temp = []
|
||||||
var updated = [{tag: "i", key: 3}]
|
var updated = [{tag: "i", key: 3}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, temp)
|
render(root, temp)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(1)
|
o(root.childNodes.length).equals(1)
|
||||||
o(updated[0].dom.nodeName).equals("I")
|
o(updated[0].dom.nodeName).equals("I")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -608,11 +608,11 @@ o.spec("updateNodes", function() {
|
||||||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
||||||
var temp = []
|
var temp = []
|
||||||
var updated = [{tag: "i", key: 3}, {tag: "s", key: 4}, {tag: "div", key: 5}]
|
var updated = [{tag: "i", key: 3}, {tag: "s", key: 4}, {tag: "div", key: 5}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, temp)
|
render(root, temp)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(3)
|
o(root.childNodes.length).equals(3)
|
||||||
o(updated[0].dom.nodeName).equals("I")
|
o(updated[0].dom.nodeName).equals("I")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -625,11 +625,11 @@ o.spec("updateNodes", function() {
|
||||||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
||||||
var temp = []
|
var temp = []
|
||||||
var updated = [{tag: "a", key: 1}, {tag: "s", key: 4}]
|
var updated = [{tag: "a", key: 1}, {tag: "s", key: 4}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, temp)
|
render(root, temp)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(2)
|
o(root.childNodes.length).equals(2)
|
||||||
o(updated[0].dom.nodeName).equals("A")
|
o(updated[0].dom.nodeName).equals("A")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -640,11 +640,11 @@ o.spec("updateNodes", function() {
|
||||||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
||||||
var temp = []
|
var temp = []
|
||||||
var updated = [{tag: "s", key: 4}, {tag: "a", key: 1}]
|
var updated = [{tag: "s", key: 4}, {tag: "a", key: 1}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, temp)
|
render(root, temp)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(2)
|
o(root.childNodes.length).equals(2)
|
||||||
o(updated[0].dom.nodeName).equals("S")
|
o(updated[0].dom.nodeName).equals("S")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -655,11 +655,11 @@ o.spec("updateNodes", function() {
|
||||||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}, {tag: "i", key: 3}]
|
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}, {tag: "i", key: 3}]
|
||||||
var temp = []
|
var temp = []
|
||||||
var updated = [{tag: "a", key: 1}, {tag: "s", key: 4}]
|
var updated = [{tag: "a", key: 1}, {tag: "s", key: 4}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, temp)
|
render(root, temp)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(2)
|
o(root.childNodes.length).equals(2)
|
||||||
o(updated[0].dom.nodeName).equals("A")
|
o(updated[0].dom.nodeName).equals("A")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -670,11 +670,11 @@ o.spec("updateNodes", function() {
|
||||||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}, {tag: "i", key: 3}]
|
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}, {tag: "i", key: 3}]
|
||||||
var temp = []
|
var temp = []
|
||||||
var updated = [{tag: "s", key: 4}, {tag: "a", key: 1}]
|
var updated = [{tag: "s", key: 4}, {tag: "a", key: 1}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, temp)
|
render(root, temp)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(2)
|
o(root.childNodes.length).equals(2)
|
||||||
o(updated[0].dom.nodeName).equals("S")
|
o(updated[0].dom.nodeName).equals("S")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -685,11 +685,11 @@ o.spec("updateNodes", function() {
|
||||||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
||||||
var temp = []
|
var temp = []
|
||||||
var updated = [{tag: "a", key: 1}, {tag: "i", key: 3}, {tag: "s", key: 4}]
|
var updated = [{tag: "a", key: 1}, {tag: "i", key: 3}, {tag: "s", key: 4}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, temp)
|
render(root, temp)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(3)
|
o(root.childNodes.length).equals(3)
|
||||||
o(updated[0].dom.nodeName).equals("A")
|
o(updated[0].dom.nodeName).equals("A")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -702,11 +702,11 @@ o.spec("updateNodes", function() {
|
||||||
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
var vnodes = [{tag: "a", key: 1}, {tag: "b", key: 2}]
|
||||||
var temp = []
|
var temp = []
|
||||||
var updated = [{tag: "s", key: 4}, {tag: "i", key: 3}, {tag: "a", key: 1}]
|
var updated = [{tag: "s", key: 4}, {tag: "i", key: 3}, {tag: "a", key: 1}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, temp)
|
render(root, temp)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(3)
|
o(root.childNodes.length).equals(3)
|
||||||
o(updated[0].dom.nodeName).equals("S")
|
o(updated[0].dom.nodeName).equals("S")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -720,12 +720,12 @@ o.spec("updateNodes", function() {
|
||||||
var temp1 = []
|
var temp1 = []
|
||||||
var temp2 = [{tag: "a", key: 1, children: [{tag: "i", key: 3}, {tag: "s", key: 4}]}, {tag: "b", key: 2}]
|
var temp2 = [{tag: "a", key: 1, children: [{tag: "i", key: 3}, {tag: "s", key: 4}]}, {tag: "b", key: 2}]
|
||||||
var updated = [{tag: "a", key: 1, children: [{tag: "s", key: 4}, {tag: "i", key: 3}]}, {tag: "b", key: 2}]
|
var updated = [{tag: "a", key: 1, children: [{tag: "s", key: 4}, {tag: "i", key: 3}]}, {tag: "b", key: 2}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, temp1)
|
render(root, temp1)
|
||||||
render(root, temp2)
|
render(root, temp2)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(2)
|
o(root.childNodes.length).equals(2)
|
||||||
o(updated[0].dom.nodeName).equals("A")
|
o(updated[0].dom.nodeName).equals("A")
|
||||||
o(updated[0].dom).equals(root.childNodes[0])
|
o(updated[0].dom).equals(root.childNodes[0])
|
||||||
|
|
@ -739,11 +739,11 @@ o.spec("updateNodes", function() {
|
||||||
var vnodes = [{tag: "a", key: 1, children: [{tag: "a", key: 3, children: [{tag: "a", key: 5}]}, {tag: "a", key: 4, children: [{tag: "a", key: 5}]}]}, {tag: "a", key: 2}]
|
var vnodes = [{tag: "a", key: 1, children: [{tag: "a", key: 3, children: [{tag: "a", key: 5}]}, {tag: "a", key: 4, children: [{tag: "a", key: 5}]}]}, {tag: "a", key: 2}]
|
||||||
var temp = []
|
var temp = []
|
||||||
var updated = [{tag: "a", key: 1, children: [{tag: "a", key: 3, children: [{tag: "a", key: 5}]}, {tag: "a", key: 4, children: [{tag: "a", key: 5}]}]}, {tag: "a", key: 2}]
|
var updated = [{tag: "a", key: 1, children: [{tag: "a", key: 3, children: [{tag: "a", key: 5}]}, {tag: "a", key: 4, children: [{tag: "a", key: 5}]}]}, {tag: "a", key: 2}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, temp)
|
render(root, temp)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(root.childNodes.length).equals(2)
|
o(root.childNodes.length).equals(2)
|
||||||
o(root.childNodes[0].childNodes.length).equals(2)
|
o(root.childNodes[0].childNodes.length).equals(2)
|
||||||
o(root.childNodes[0].childNodes[0].childNodes.length).equals(1)
|
o(root.childNodes[0].childNodes[0].childNodes.length).equals(1)
|
||||||
|
|
@ -754,11 +754,11 @@ o.spec("updateNodes", function() {
|
||||||
var vnodes = [{tag: "div", key: 1}]
|
var vnodes = [{tag: "div", key: 1}]
|
||||||
var temp = []
|
var temp = []
|
||||||
var updated = [{tag: "div", key: 1}]
|
var updated = [{tag: "div", key: 1}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, temp)
|
render(root, temp)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(vnodes[0].dom).equals(updated[0].dom)
|
o(vnodes[0].dom).equals(updated[0].dom)
|
||||||
o(updated[0].dom.nodeName).equals("DIV")
|
o(updated[0].dom.nodeName).equals("DIV")
|
||||||
})
|
})
|
||||||
|
|
@ -766,11 +766,11 @@ o.spec("updateNodes", function() {
|
||||||
var vnodes = [{tag: "div", key: 1}]
|
var vnodes = [{tag: "div", key: 1}]
|
||||||
var temp = [{tag: "div"}]
|
var temp = [{tag: "div"}]
|
||||||
var updated = [{tag: "div", key: 1}]
|
var updated = [{tag: "div", key: 1}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, temp)
|
render(root, temp)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(vnodes[0].dom).equals(updated[0].dom)
|
o(vnodes[0].dom).equals(updated[0].dom)
|
||||||
o(updated[0].dom.nodeName).equals("DIV")
|
o(updated[0].dom.nodeName).equals("DIV")
|
||||||
})
|
})
|
||||||
|
|
@ -778,11 +778,11 @@ o.spec("updateNodes", function() {
|
||||||
var vnodes = [{tag: "div", children: [{tag: "a", key: 1}]}]
|
var vnodes = [{tag: "div", children: [{tag: "a", key: 1}]}]
|
||||||
var temp = [{tag: "div"}]
|
var temp = [{tag: "div"}]
|
||||||
var updated = [{tag: "div", children: [{tag: "a", key: 1}]}]
|
var updated = [{tag: "div", children: [{tag: "a", key: 1}]}]
|
||||||
|
|
||||||
render(root, vnodes)
|
render(root, vnodes)
|
||||||
render(root, temp)
|
render(root, temp)
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(vnodes[0].dom.firstChild).equals(updated[0].dom.firstChild)
|
o(vnodes[0].dom.firstChild).equals(updated[0].dom.firstChild)
|
||||||
o(updated[0].dom.firstChild.nodeName).equals("A")
|
o(updated[0].dom.firstChild.nodeName).equals("A")
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,10 @@ o.spec("updateText", function() {
|
||||||
o("updates to string", function() {
|
o("updates to string", function() {
|
||||||
var vnode = {tag: "#", children: "a"}
|
var vnode = {tag: "#", children: "a"}
|
||||||
var updated = {tag: "#", children: "b"}
|
var updated = {tag: "#", children: "b"}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(updated.dom).equals(vnode.dom)
|
o(updated.dom).equals(vnode.dom)
|
||||||
o(updated.dom).equals(root.firstChild)
|
o(updated.dom).equals(root.firstChild)
|
||||||
o(updated.dom.nodeValue).equals("b")
|
o(updated.dom.nodeValue).equals("b")
|
||||||
|
|
@ -26,10 +26,10 @@ o.spec("updateText", function() {
|
||||||
o("updates to falsy string", function() {
|
o("updates to falsy string", function() {
|
||||||
var vnode = {tag: "#", children: "a"}
|
var vnode = {tag: "#", children: "a"}
|
||||||
var updated = {tag: "#", children: ""}
|
var updated = {tag: "#", children: ""}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(updated.dom).equals(vnode.dom)
|
o(updated.dom).equals(vnode.dom)
|
||||||
o(updated.dom).equals(root.firstChild)
|
o(updated.dom).equals(root.firstChild)
|
||||||
o(updated.dom.nodeValue).equals("")
|
o(updated.dom.nodeValue).equals("")
|
||||||
|
|
@ -37,10 +37,10 @@ o.spec("updateText", function() {
|
||||||
o("updates from falsy string", function() {
|
o("updates from falsy string", function() {
|
||||||
var vnode = {tag: "#", children: ""}
|
var vnode = {tag: "#", children: ""}
|
||||||
var updated = {tag: "#", children: "b"}
|
var updated = {tag: "#", children: "b"}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(updated.dom).equals(vnode.dom)
|
o(updated.dom).equals(vnode.dom)
|
||||||
o(updated.dom).equals(root.firstChild)
|
o(updated.dom).equals(root.firstChild)
|
||||||
o(updated.dom.nodeValue).equals("b")
|
o(updated.dom.nodeValue).equals("b")
|
||||||
|
|
@ -48,10 +48,10 @@ o.spec("updateText", function() {
|
||||||
o("updates to number", function() {
|
o("updates to number", function() {
|
||||||
var vnode = {tag: "#", children: "a"}
|
var vnode = {tag: "#", children: "a"}
|
||||||
var updated = {tag: "#", children: 1}
|
var updated = {tag: "#", children: 1}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(updated.dom).equals(vnode.dom)
|
o(updated.dom).equals(vnode.dom)
|
||||||
o(updated.dom).equals(root.firstChild)
|
o(updated.dom).equals(root.firstChild)
|
||||||
o(updated.dom.nodeValue).equals("1")
|
o(updated.dom.nodeValue).equals("1")
|
||||||
|
|
@ -59,10 +59,10 @@ o.spec("updateText", function() {
|
||||||
o("updates to falsy number", function() {
|
o("updates to falsy number", function() {
|
||||||
var vnode = {tag: "#", children: "a"}
|
var vnode = {tag: "#", children: "a"}
|
||||||
var updated = {tag: "#", children: 0}
|
var updated = {tag: "#", children: 0}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(updated.dom).equals(vnode.dom)
|
o(updated.dom).equals(vnode.dom)
|
||||||
o(updated.dom).equals(root.firstChild)
|
o(updated.dom).equals(root.firstChild)
|
||||||
o(updated.dom.nodeValue).equals("0")
|
o(updated.dom.nodeValue).equals("0")
|
||||||
|
|
@ -70,10 +70,10 @@ o.spec("updateText", function() {
|
||||||
o("updates from falsy number", function() {
|
o("updates from falsy number", function() {
|
||||||
var vnode = {tag: "#", children: 0}
|
var vnode = {tag: "#", children: 0}
|
||||||
var updated = {tag: "#", children: "b"}
|
var updated = {tag: "#", children: "b"}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(updated.dom).equals(vnode.dom)
|
o(updated.dom).equals(vnode.dom)
|
||||||
o(updated.dom).equals(root.firstChild)
|
o(updated.dom).equals(root.firstChild)
|
||||||
o(updated.dom.nodeValue).equals("b")
|
o(updated.dom.nodeValue).equals("b")
|
||||||
|
|
@ -81,10 +81,10 @@ o.spec("updateText", function() {
|
||||||
o("updates to boolean", function() {
|
o("updates to boolean", function() {
|
||||||
var vnode = {tag: "#", children: "a"}
|
var vnode = {tag: "#", children: "a"}
|
||||||
var updated = {tag: "#", children: true}
|
var updated = {tag: "#", children: true}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(updated.dom).equals(vnode.dom)
|
o(updated.dom).equals(vnode.dom)
|
||||||
o(updated.dom).equals(root.firstChild)
|
o(updated.dom).equals(root.firstChild)
|
||||||
o(updated.dom.nodeValue).equals("true")
|
o(updated.dom.nodeValue).equals("true")
|
||||||
|
|
@ -92,10 +92,10 @@ o.spec("updateText", function() {
|
||||||
o("updates to falsy boolean", function() {
|
o("updates to falsy boolean", function() {
|
||||||
var vnode = {tag: "#", children: "a"}
|
var vnode = {tag: "#", children: "a"}
|
||||||
var updated = {tag: "#", children: false}
|
var updated = {tag: "#", children: false}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(updated.dom).equals(vnode.dom)
|
o(updated.dom).equals(vnode.dom)
|
||||||
o(updated.dom).equals(root.firstChild)
|
o(updated.dom).equals(root.firstChild)
|
||||||
o(updated.dom.nodeValue).equals("false")
|
o(updated.dom.nodeValue).equals("false")
|
||||||
|
|
@ -103,10 +103,10 @@ o.spec("updateText", function() {
|
||||||
o("updates from falsy boolean", function() {
|
o("updates from falsy boolean", function() {
|
||||||
var vnode = {tag: "#", children: false}
|
var vnode = {tag: "#", children: false}
|
||||||
var updated = {tag: "#", children: "b"}
|
var updated = {tag: "#", children: "b"}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
o(updated.dom).equals(vnode.dom)
|
o(updated.dom).equals(vnode.dom)
|
||||||
o(updated.dom).equals(root.firstChild)
|
o(updated.dom).equals(root.firstChild)
|
||||||
o(updated.dom.nodeValue).equals("b")
|
o(updated.dom.nodeValue).equals("b")
|
||||||
|
|
|
||||||
|
|
@ -4,4 +4,4 @@ var Node = require("../render/node")
|
||||||
|
|
||||||
module.exports = function(html) {
|
module.exports = function(html) {
|
||||||
return Node("<", undefined, undefined, html, undefined, undefined)
|
return Node("<", undefined, undefined, html, undefined, undefined)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,27 +8,27 @@ module.exports = function($window, Promise) {
|
||||||
function xhr(args) {
|
function xhr(args) {
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
var useBody = typeof args.useBody === "boolean" ? args.useBody : args.method !== "GET" && args.method !== "TRACE"
|
var useBody = typeof args.useBody === "boolean" ? args.useBody : args.method !== "GET" && args.method !== "TRACE"
|
||||||
|
|
||||||
if (typeof args.serialize !== "function") args.serialize = JSON.stringify
|
if (typeof args.serialize !== "function") args.serialize = JSON.stringify
|
||||||
if (typeof args.deserialize !== "function") args.deserialize = deserialize
|
if (typeof args.deserialize !== "function") args.deserialize = deserialize
|
||||||
if (typeof args.extract !== "function") args.extract = extract
|
if (typeof args.extract !== "function") args.extract = extract
|
||||||
|
|
||||||
args.url = interpolate(args.url, args.data)
|
args.url = interpolate(args.url, args.data)
|
||||||
if (useBody) args.data = args.serialize(args.data)
|
if (useBody) args.data = args.serialize(args.data)
|
||||||
else args.url = assemble(args.url, args.data)
|
else args.url = assemble(args.url, args.data)
|
||||||
|
|
||||||
var xhr = new $window.XMLHttpRequest()
|
var xhr = new $window.XMLHttpRequest()
|
||||||
xhr.open(args.method, args.url, typeof args.async === "boolean" ? args.async : true, typeof args.user === "string" ? args.user : undefined, typeof args.password === "string" ? args.password : undefined)
|
xhr.open(args.method, args.url, typeof args.async === "boolean" ? args.async : true, typeof args.user === "string" ? args.user : undefined, typeof args.password === "string" ? args.password : undefined)
|
||||||
|
|
||||||
if (args.serialize === JSON.stringify && useBody) {
|
if (args.serialize === JSON.stringify && useBody) {
|
||||||
xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8")
|
xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8")
|
||||||
}
|
}
|
||||||
if (args.deserialize === deserialize) {
|
if (args.deserialize === deserialize) {
|
||||||
xhr.setRequestHeader("Accept", "application/json, text/*")
|
xhr.setRequestHeader("Accept", "application/json, text/*")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof args.config === "function") xhr = args.config(xhr, args) || xhr
|
if (typeof args.config === "function") xhr = args.config(xhr, args) || xhr
|
||||||
|
|
||||||
xhr.onreadystatechange = function() {
|
xhr.onreadystatechange = function() {
|
||||||
if (xhr.readyState === 4) {
|
if (xhr.readyState === 4) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -42,7 +42,7 @@ module.exports = function($window, Promise) {
|
||||||
}
|
}
|
||||||
else response = new args.type(response)
|
else response = new args.type(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve(response)
|
resolve(response)
|
||||||
}
|
}
|
||||||
else reject(new Error(xhr.responseText))
|
else reject(new Error(xhr.responseText))
|
||||||
|
|
@ -52,7 +52,7 @@ module.exports = function($window, Promise) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (useBody) xhr.send(args.data)
|
if (useBody) xhr.send(args.data)
|
||||||
else xhr.send()
|
else xhr.send()
|
||||||
})
|
})
|
||||||
|
|
@ -82,7 +82,7 @@ module.exports = function($window, Promise) {
|
||||||
|
|
||||||
function interpolate(url, data) {
|
function interpolate(url, data) {
|
||||||
if (data == null) return url
|
if (data == null) return url
|
||||||
|
|
||||||
var tokens = url.match(/:[^\/]+/gi) || []
|
var tokens = url.match(/:[^\/]+/gi) || []
|
||||||
for (var i = 0; i < tokens.length; i++) {
|
for (var i = 0; i < tokens.length; i++) {
|
||||||
var key = tokens[i].slice(1)
|
var key = tokens[i].slice(1)
|
||||||
|
|
@ -109,6 +109,6 @@ module.exports = function($window, Promise) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function extract(xhr) {return xhr.responseText}
|
function extract(xhr) {return xhr.responseText}
|
||||||
|
|
||||||
return {xhr: xhr, jsonp: jsonp}
|
return {xhr: xhr, jsonp: jsonp}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
<script src="../../request/request.js"></script>
|
<script src="../../request/request.js"></script>
|
||||||
<script src="test-xhr.js"></script>
|
<script src="test-xhr.js"></script>
|
||||||
<script src="test-jsonp.js"></script>
|
<script src="test-jsonp.js"></script>
|
||||||
|
|
||||||
<script>require("../../ospec/ospec").run()</script>
|
<script>require("../../ospec/ospec").run()</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ o.spec("jsonp", function() {
|
||||||
mock = xhrMock()
|
mock = xhrMock()
|
||||||
jsonp = new Request(mock, Promise).jsonp
|
jsonp = new Request(mock, Promise).jsonp
|
||||||
})
|
})
|
||||||
|
|
||||||
o("works", function(done) {
|
o("works", function(done) {
|
||||||
mock.$defineRoutes({
|
mock.$defineRoutes({
|
||||||
"GET /item": function(request) {
|
"GET /item": function(request) {
|
||||||
|
|
@ -52,4 +52,4 @@ o.spec("jsonp", function() {
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ o.spec("xhr", function() {
|
||||||
mock = xhrMock()
|
mock = xhrMock()
|
||||||
xhr = new Request(mock, Promise).xhr
|
xhr = new Request(mock, Promise).xhr
|
||||||
})
|
})
|
||||||
|
|
||||||
o.spec("success", function() {
|
o.spec("success", function() {
|
||||||
o("works via GET", function(done) {
|
o("works via GET", function(done) {
|
||||||
var s = new Date
|
var s = new Date
|
||||||
|
|
@ -119,7 +119,7 @@ o.spec("xhr", function() {
|
||||||
var Entity = function(args) {
|
var Entity = function(args) {
|
||||||
return {_id: args.id}
|
return {_id: args.id}
|
||||||
}
|
}
|
||||||
|
|
||||||
mock.$defineRoutes({
|
mock.$defineRoutes({
|
||||||
"GET /item": function(request) {
|
"GET /item": function(request) {
|
||||||
return {status: 200, responseText: JSON.stringify([{id: 1}, {id: 2}, {id: 3}])}
|
return {status: 200, responseText: JSON.stringify([{id: 1}, {id: 2}, {id: 3}])}
|
||||||
|
|
@ -133,7 +133,7 @@ o.spec("xhr", function() {
|
||||||
var Entity = function(args) {
|
var Entity = function(args) {
|
||||||
return {_id: args.id}
|
return {_id: args.id}
|
||||||
}
|
}
|
||||||
|
|
||||||
mock.$defineRoutes({
|
mock.$defineRoutes({
|
||||||
"GET /item": function(request) {
|
"GET /item": function(request) {
|
||||||
return {status: 200, responseText: JSON.stringify({id: 1})}
|
return {status: 200, responseText: JSON.stringify({id: 1})}
|
||||||
|
|
@ -147,7 +147,7 @@ o.spec("xhr", function() {
|
||||||
var serialize = function(data) {
|
var serialize = function(data) {
|
||||||
return "id=" + data.id
|
return "id=" + data.id
|
||||||
}
|
}
|
||||||
|
|
||||||
mock.$defineRoutes({
|
mock.$defineRoutes({
|
||||||
"GET /item": function(request) {
|
"GET /item": function(request) {
|
||||||
return {status: 200, responseText: JSON.stringify({body: request.query})}
|
return {status: 200, responseText: JSON.stringify({body: request.query})}
|
||||||
|
|
@ -161,7 +161,7 @@ o.spec("xhr", function() {
|
||||||
var serialize = function(data) {
|
var serialize = function(data) {
|
||||||
return "id=" + data.id
|
return "id=" + data.id
|
||||||
}
|
}
|
||||||
|
|
||||||
mock.$defineRoutes({
|
mock.$defineRoutes({
|
||||||
"POST /item": function(request) {
|
"POST /item": function(request) {
|
||||||
return {status: 200, responseText: JSON.stringify({body: request.body})}
|
return {status: 200, responseText: JSON.stringify({body: request.body})}
|
||||||
|
|
@ -175,7 +175,7 @@ o.spec("xhr", function() {
|
||||||
var deserialize = function(data) {
|
var deserialize = function(data) {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
mock.$defineRoutes({
|
mock.$defineRoutes({
|
||||||
"GET /item": function(request) {
|
"GET /item": function(request) {
|
||||||
return {status: 200, responseText: JSON.stringify({test: 123})}
|
return {status: 200, responseText: JSON.stringify({test: 123})}
|
||||||
|
|
@ -189,7 +189,7 @@ o.spec("xhr", function() {
|
||||||
var deserialize = function(data) {
|
var deserialize = function(data) {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
mock.$defineRoutes({
|
mock.$defineRoutes({
|
||||||
"POST /item": function(request) {
|
"POST /item": function(request) {
|
||||||
return {status: 200, responseText: JSON.stringify({test: 123})}
|
return {status: 200, responseText: JSON.stringify({test: 123})}
|
||||||
|
|
@ -203,7 +203,7 @@ o.spec("xhr", function() {
|
||||||
var extract = function(data) {
|
var extract = function(data) {
|
||||||
return JSON.stringify({test: 123})
|
return JSON.stringify({test: 123})
|
||||||
}
|
}
|
||||||
|
|
||||||
mock.$defineRoutes({
|
mock.$defineRoutes({
|
||||||
"GET /item": function(request) {
|
"GET /item": function(request) {
|
||||||
return {status: 200, responseText: ""}
|
return {status: 200, responseText: ""}
|
||||||
|
|
@ -217,7 +217,7 @@ o.spec("xhr", function() {
|
||||||
var extract = function(data) {
|
var extract = function(data) {
|
||||||
return JSON.stringify({test: 123})
|
return JSON.stringify({test: 123})
|
||||||
}
|
}
|
||||||
|
|
||||||
mock.$defineRoutes({
|
mock.$defineRoutes({
|
||||||
"POST /item": function(request) {
|
"POST /item": function(request) {
|
||||||
return {status: 200, responseText: ""}
|
return {status: 200, responseText: ""}
|
||||||
|
|
@ -234,7 +234,7 @@ o.spec("xhr", function() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
xhr({method: "POST", url: "/item", config: config}).then(done)
|
xhr({method: "POST", url: "/item", config: config}).then(done)
|
||||||
|
|
||||||
function config(xhr) {
|
function config(xhr) {
|
||||||
o(typeof xhr.setRequestHeader).equals("function")
|
o(typeof xhr.setRequestHeader).equals("function")
|
||||||
o(typeof xhr.open).equals("function")
|
o(typeof xhr.open).equals("function")
|
||||||
|
|
@ -264,4 +264,4 @@ o.spec("xhr", function() {
|
||||||
}).then(done)
|
}).then(done)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -5,16 +5,16 @@ var parseQueryString = require("../querystring/parse")
|
||||||
|
|
||||||
module.exports = function($window) {
|
module.exports = function($window) {
|
||||||
var supportsPushState = typeof $window.history.pushState === "function" && $window.location.protocol !== "file:"
|
var supportsPushState = typeof $window.history.pushState === "function" && $window.location.protocol !== "file:"
|
||||||
|
|
||||||
var prefix = "#!"
|
var prefix = "#!"
|
||||||
function setPrefix(value) {prefix = value}
|
function setPrefix(value) {prefix = value}
|
||||||
|
|
||||||
function normalize(fragment) {
|
function normalize(fragment) {
|
||||||
var data = $window.location[fragment].replace(/(?:%[a-f89][a-f0-9])+/gim, decodeURIComponent)
|
var data = $window.location[fragment].replace(/(?:%[a-f89][a-f0-9])+/gim, decodeURIComponent)
|
||||||
if (fragment === "pathname" && data[0] !== "/") data = "/" + data
|
if (fragment === "pathname" && data[0] !== "/") data = "/" + data
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
function parsePath(path, queryData, hashData) {
|
function parsePath(path, queryData, hashData) {
|
||||||
var queryIndex = path.indexOf("?")
|
var queryIndex = path.indexOf("?")
|
||||||
var hashIndex = path.indexOf("#")
|
var hashIndex = path.indexOf("#")
|
||||||
|
|
@ -50,13 +50,13 @@ module.exports = function($window) {
|
||||||
return data[token]
|
return data[token]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var query = buildQueryString(queryData)
|
var query = buildQueryString(queryData)
|
||||||
if (query) path += "?" + query
|
if (query) path += "?" + query
|
||||||
|
|
||||||
var hash = buildQueryString(hashData)
|
var hash = buildQueryString(hashData)
|
||||||
if (hash) path += "#" + hash
|
if (hash) path += "#" + hash
|
||||||
|
|
||||||
if (supportsPushState) {
|
if (supportsPushState) {
|
||||||
if (options && options.replace) $window.history.replaceState(null, null, prefix + path)
|
if (options && options.replace) $window.history.replaceState(null, null, prefix + path)
|
||||||
else $window.history.pushState(null, null, prefix + path)
|
else $window.history.pushState(null, null, prefix + path)
|
||||||
|
|
@ -64,20 +64,20 @@ module.exports = function($window) {
|
||||||
}
|
}
|
||||||
else $window.location.href = prefix + path
|
else $window.location.href = prefix + path
|
||||||
}
|
}
|
||||||
|
|
||||||
function defineRoutes(routes, resolve, reject) {
|
function defineRoutes(routes, resolve, reject) {
|
||||||
if (supportsPushState) $window.onpopstate = resolveRoute
|
if (supportsPushState) $window.onpopstate = resolveRoute
|
||||||
else if (prefix.charAt(0) === "#") $window.onhashchange = resolveRoute
|
else if (prefix.charAt(0) === "#") $window.onhashchange = resolveRoute
|
||||||
resolveRoute()
|
resolveRoute()
|
||||||
|
|
||||||
function resolveRoute() {
|
function resolveRoute() {
|
||||||
var path = getPath()
|
var path = getPath()
|
||||||
var params = {}
|
var params = {}
|
||||||
var pathname = parsePath(path, params, params)
|
var pathname = parsePath(path, params, params)
|
||||||
|
|
||||||
for (var route in routes) {
|
for (var route in routes) {
|
||||||
var matcher = new RegExp("^" + route.replace(/:[^\/]+?\.{3}/g, "(.*?)").replace(/:[^\/]+/g, "([^\\/]+)") + "\/?$")
|
var matcher = new RegExp("^" + route.replace(/:[^\/]+?\.{3}/g, "(.*?)").replace(/:[^\/]+/g, "([^\\/]+)") + "\/?$")
|
||||||
|
|
||||||
if (matcher.test(pathname)) {
|
if (matcher.test(pathname)) {
|
||||||
pathname.replace(matcher, function() {
|
pathname.replace(matcher, function() {
|
||||||
var keys = route.match(/:[^\/]+/g) || []
|
var keys = route.match(/:[^\/]+/g) || []
|
||||||
|
|
@ -90,12 +90,12 @@ module.exports = function($window) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
reject(path, params)
|
reject(path, params)
|
||||||
}
|
}
|
||||||
return resolveRoute
|
return resolveRoute
|
||||||
}
|
}
|
||||||
|
|
||||||
function link(vnode) {
|
function link(vnode) {
|
||||||
vnode.dom.setAttribute("href", prefix + vnode.attrs.href)
|
vnode.dom.setAttribute("href", prefix + vnode.attrs.href)
|
||||||
vnode.dom.onclick = function(e) {
|
vnode.dom.onclick = function(e) {
|
||||||
|
|
@ -103,6 +103,6 @@ module.exports = function($window) {
|
||||||
setPath(vnode.attrs.href, undefined, undefined)
|
setPath(vnode.attrs.href, undefined, undefined)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {setPrefix: setPrefix, getPath: getPath, setPath: setPath, defineRoutes: defineRoutes, link: link}
|
return {setPrefix: setPrefix, getPath: getPath, setPath: setPath, defineRoutes: defineRoutes, link: link}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
<script src="test-defineRoutes.js"></script>
|
<script src="test-defineRoutes.js"></script>
|
||||||
<script src="test-getPath.js"></script>
|
<script src="test-getPath.js"></script>
|
||||||
<script src="test-setPath.js"></script>
|
<script src="test-setPath.js"></script>
|
||||||
|
|
||||||
<script>require("../../ospec/ospec").run()</script>
|
<script>require("../../ospec/ospec").run()</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ o.spec("Router.defineRoutes", function() {
|
||||||
void ["#", "?", "", "#!", "?!", "/foo"].forEach(function(prefix) {
|
void ["#", "?", "", "#!", "?!", "/foo"].forEach(function(prefix) {
|
||||||
o.spec("using prefix `" + prefix + "`", function() {
|
o.spec("using prefix `" + prefix + "`", function() {
|
||||||
var $window, router, onRouteChange, onFail
|
var $window, router, onRouteChange, onFail
|
||||||
|
|
||||||
o.beforeEach(function() {
|
o.beforeEach(function() {
|
||||||
$window = pushStateMock()
|
$window = pushStateMock()
|
||||||
router = new Router($window)
|
router = new Router($window)
|
||||||
|
|
@ -16,195 +16,195 @@ o.spec("Router.defineRoutes", function() {
|
||||||
onRouteChange = o.spy()
|
onRouteChange = o.spy()
|
||||||
onFail = o.spy()
|
onFail = o.spy()
|
||||||
})
|
})
|
||||||
|
|
||||||
o("resolves to route", function() {
|
o("resolves to route", function() {
|
||||||
$window.location.href = prefix + "/test"
|
$window.location.href = prefix + "/test"
|
||||||
router.defineRoutes({"/test": {data: 1}}, onRouteChange, onFail)
|
router.defineRoutes({"/test": {data: 1}}, onRouteChange, onFail)
|
||||||
|
|
||||||
o(onRouteChange.callCount).equals(1)
|
o(onRouteChange.callCount).equals(1)
|
||||||
o(onRouteChange.args).deepEquals([{data: 1}, {}, "/test", "/test"])
|
o(onRouteChange.args).deepEquals([{data: 1}, {}, "/test", "/test"])
|
||||||
o(onFail.callCount).equals(0)
|
o(onFail.callCount).equals(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
o("resolves to route w/ escaped unicode", function() {
|
o("resolves to route w/ escaped unicode", function() {
|
||||||
$window.location.href = prefix + "/%C3%B6?%C3%B6=%C3%B6#%C3%B6=%C3%B6"
|
$window.location.href = prefix + "/%C3%B6?%C3%B6=%C3%B6#%C3%B6=%C3%B6"
|
||||||
router.defineRoutes({"/ö": {data: 2}}, onRouteChange, onFail)
|
router.defineRoutes({"/ö": {data: 2}}, onRouteChange, onFail)
|
||||||
|
|
||||||
o(onRouteChange.callCount).equals(1)
|
o(onRouteChange.callCount).equals(1)
|
||||||
o(onRouteChange.args).deepEquals([{data: 2}, {"ö": "ö"}, "/ö?ö=ö#ö=ö", "/ö"])
|
o(onRouteChange.args).deepEquals([{data: 2}, {"ö": "ö"}, "/ö?ö=ö#ö=ö", "/ö"])
|
||||||
o(onFail.callCount).equals(0)
|
o(onFail.callCount).equals(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
o("resolves to route w/ unicode", function() {
|
o("resolves to route w/ unicode", function() {
|
||||||
$window.location.href = prefix + "/ö?ö=ö#ö=ö"
|
$window.location.href = prefix + "/ö?ö=ö#ö=ö"
|
||||||
router.defineRoutes({"/ö": {data: 2}}, onRouteChange, onFail)
|
router.defineRoutes({"/ö": {data: 2}}, onRouteChange, onFail)
|
||||||
|
|
||||||
o(onRouteChange.callCount).equals(1)
|
o(onRouteChange.callCount).equals(1)
|
||||||
o(onRouteChange.args).deepEquals([{data: 2}, {"ö": "ö"}, "/ö?ö=ö#ö=ö", "/ö"])
|
o(onRouteChange.args).deepEquals([{data: 2}, {"ö": "ö"}, "/ö?ö=ö#ö=ö", "/ö"])
|
||||||
o(onFail.callCount).equals(0)
|
o(onFail.callCount).equals(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
o("resolves to route on fallback mode", function() {
|
o("resolves to route on fallback mode", function() {
|
||||||
$window.location.href = "file://" + prefix + "/test"
|
$window.location.href = "file://" + prefix + "/test"
|
||||||
|
|
||||||
router = new Router($window)
|
router = new Router($window)
|
||||||
router.setPrefix(prefix)
|
router.setPrefix(prefix)
|
||||||
|
|
||||||
router.defineRoutes({"/test": {data: 1}}, onRouteChange, onFail)
|
router.defineRoutes({"/test": {data: 1}}, onRouteChange, onFail)
|
||||||
|
|
||||||
o(onRouteChange.callCount).equals(1)
|
o(onRouteChange.callCount).equals(1)
|
||||||
o(onRouteChange.args).deepEquals([{data: 1}, {}, "/test", "/test"])
|
o(onRouteChange.args).deepEquals([{data: 1}, {}, "/test", "/test"])
|
||||||
o(onFail.callCount).equals(0)
|
o(onFail.callCount).equals(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
o("handles parameterized route", function() {
|
o("handles parameterized route", function() {
|
||||||
$window.location.href = prefix + "/test/x"
|
$window.location.href = prefix + "/test/x"
|
||||||
router.defineRoutes({"/test/:a": {data: 1}}, onRouteChange, onFail)
|
router.defineRoutes({"/test/:a": {data: 1}}, onRouteChange, onFail)
|
||||||
|
|
||||||
o(onRouteChange.callCount).equals(1)
|
o(onRouteChange.callCount).equals(1)
|
||||||
o(onRouteChange.args).deepEquals([{data: 1}, {a: "x"}, "/test/x", "/test/:a"])
|
o(onRouteChange.args).deepEquals([{data: 1}, {a: "x"}, "/test/x", "/test/:a"])
|
||||||
o(onFail.callCount).equals(0)
|
o(onFail.callCount).equals(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
o("handles multi-parameterized route", function() {
|
o("handles multi-parameterized route", function() {
|
||||||
$window.location.href = prefix + "/test/x/y"
|
$window.location.href = prefix + "/test/x/y"
|
||||||
router.defineRoutes({"/test/:a/:b": {data: 1}}, onRouteChange, onFail)
|
router.defineRoutes({"/test/:a/:b": {data: 1}}, onRouteChange, onFail)
|
||||||
|
|
||||||
o(onRouteChange.callCount).equals(1)
|
o(onRouteChange.callCount).equals(1)
|
||||||
o(onRouteChange.args).deepEquals([{data: 1}, {a: "x", b: "y"}, "/test/x/y", "/test/:a/:b"])
|
o(onRouteChange.args).deepEquals([{data: 1}, {a: "x", b: "y"}, "/test/x/y", "/test/:a/:b"])
|
||||||
o(onFail.callCount).equals(0)
|
o(onFail.callCount).equals(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
o("handles rest parameterized route", function() {
|
o("handles rest parameterized route", function() {
|
||||||
$window.location.href = prefix + "/test/x/y"
|
$window.location.href = prefix + "/test/x/y"
|
||||||
router.defineRoutes({"/test/:a...": {data: 1}}, onRouteChange, onFail)
|
router.defineRoutes({"/test/:a...": {data: 1}}, onRouteChange, onFail)
|
||||||
|
|
||||||
o(onRouteChange.callCount).equals(1)
|
o(onRouteChange.callCount).equals(1)
|
||||||
o(onRouteChange.args).deepEquals([{data: 1}, {a: "x/y"}, "/test/x/y", "/test/:a..."])
|
o(onRouteChange.args).deepEquals([{data: 1}, {a: "x/y"}, "/test/x/y", "/test/:a..."])
|
||||||
o(onFail.callCount).equals(0)
|
o(onFail.callCount).equals(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
o("handles route with search", function() {
|
o("handles route with search", function() {
|
||||||
$window.location.href = prefix + "/test?a=b&c=d"
|
$window.location.href = prefix + "/test?a=b&c=d"
|
||||||
router.defineRoutes({"/test": {data: 1}}, onRouteChange, onFail)
|
router.defineRoutes({"/test": {data: 1}}, onRouteChange, onFail)
|
||||||
|
|
||||||
o(onRouteChange.callCount).equals(1)
|
o(onRouteChange.callCount).equals(1)
|
||||||
o(onRouteChange.args).deepEquals([{data: 1}, {a: "b", c: "d"}, "/test?a=b&c=d", "/test"])
|
o(onRouteChange.args).deepEquals([{data: 1}, {a: "b", c: "d"}, "/test?a=b&c=d", "/test"])
|
||||||
o(onFail.callCount).equals(0)
|
o(onFail.callCount).equals(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
o("handles route with hash", function() {
|
o("handles route with hash", function() {
|
||||||
$window.location.href = prefix + "/test#a=b&c=d"
|
$window.location.href = prefix + "/test#a=b&c=d"
|
||||||
router.defineRoutes({"/test": {data: 1}}, onRouteChange, onFail)
|
router.defineRoutes({"/test": {data: 1}}, onRouteChange, onFail)
|
||||||
|
|
||||||
o(onRouteChange.callCount).equals(1)
|
o(onRouteChange.callCount).equals(1)
|
||||||
o(onRouteChange.args).deepEquals([{data: 1}, {a: "b", c: "d"}, "/test#a=b&c=d", "/test"])
|
o(onRouteChange.args).deepEquals([{data: 1}, {a: "b", c: "d"}, "/test#a=b&c=d", "/test"])
|
||||||
o(onFail.callCount).equals(0)
|
o(onFail.callCount).equals(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
o("handles route with search and hash", function() {
|
o("handles route with search and hash", function() {
|
||||||
$window.location.href = prefix + "/test?a=b#c=d"
|
$window.location.href = prefix + "/test?a=b#c=d"
|
||||||
router.defineRoutes({"/test": {data: 1}}, onRouteChange, onFail)
|
router.defineRoutes({"/test": {data: 1}}, onRouteChange, onFail)
|
||||||
|
|
||||||
o(onRouteChange.callCount).equals(1)
|
o(onRouteChange.callCount).equals(1)
|
||||||
o(onRouteChange.args).deepEquals([{data: 1}, {a: "b", c: "d"}, "/test?a=b#c=d", "/test"])
|
o(onRouteChange.args).deepEquals([{data: 1}, {a: "b", c: "d"}, "/test?a=b#c=d", "/test"])
|
||||||
o(onFail.callCount).equals(0)
|
o(onFail.callCount).equals(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
o("calls reject", function() {
|
o("calls reject", function() {
|
||||||
$window.location.href = prefix + "/test"
|
$window.location.href = prefix + "/test"
|
||||||
router.defineRoutes({"/other": {data: 1}}, onRouteChange, onFail)
|
router.defineRoutes({"/other": {data: 1}}, onRouteChange, onFail)
|
||||||
|
|
||||||
o(onFail.callCount).equals(1)
|
o(onFail.callCount).equals(1)
|
||||||
o(onFail.args).deepEquals(["/test", {}])
|
o(onFail.args).deepEquals(["/test", {}])
|
||||||
})
|
})
|
||||||
|
|
||||||
o("calls reject w/ search and hash", function() {
|
o("calls reject w/ search and hash", function() {
|
||||||
$window.location.href = prefix + "/test?a=b#c=d"
|
$window.location.href = prefix + "/test?a=b#c=d"
|
||||||
router.defineRoutes({"/other": {data: 1}}, onRouteChange, onFail)
|
router.defineRoutes({"/other": {data: 1}}, onRouteChange, onFail)
|
||||||
|
|
||||||
o(onFail.callCount).equals(1)
|
o(onFail.callCount).equals(1)
|
||||||
o(onFail.args).deepEquals(["/test?a=b#c=d", {a: "b", c: "d"}])
|
o(onFail.args).deepEquals(["/test?a=b#c=d", {a: "b", c: "d"}])
|
||||||
})
|
})
|
||||||
|
|
||||||
o("handles out of order routes", function() {
|
o("handles out of order routes", function() {
|
||||||
$window.location.href = prefix + "/z/y/x"
|
$window.location.href = prefix + "/z/y/x"
|
||||||
router.defineRoutes({"/z/y/x": {data: 1}, "/:a...": {data: 2}}, onRouteChange, onFail)
|
router.defineRoutes({"/z/y/x": {data: 1}, "/:a...": {data: 2}}, onRouteChange, onFail)
|
||||||
|
|
||||||
o(onRouteChange.callCount).equals(1)
|
o(onRouteChange.callCount).equals(1)
|
||||||
o(onRouteChange.args).deepEquals([{data: 1}, {}, "/z/y/x", "/z/y/x"])
|
o(onRouteChange.args).deepEquals([{data: 1}, {}, "/z/y/x", "/z/y/x"])
|
||||||
})
|
})
|
||||||
|
|
||||||
o("handles reverse out of order routes", function() {
|
o("handles reverse out of order routes", function() {
|
||||||
$window.location.href = prefix + "/z/y/x"
|
$window.location.href = prefix + "/z/y/x"
|
||||||
router.defineRoutes({"/:a...": {data: 2}, "/z/y/x": {data: 1}}, onRouteChange, onFail)
|
router.defineRoutes({"/:a...": {data: 2}, "/z/y/x": {data: 1}}, onRouteChange, onFail)
|
||||||
|
|
||||||
o(onRouteChange.callCount).equals(1)
|
o(onRouteChange.callCount).equals(1)
|
||||||
o(onRouteChange.args).deepEquals([{data: 2}, {a: "z/y/x"}, "/z/y/x", "/:a..."])
|
o(onRouteChange.args).deepEquals([{data: 2}, {a: "z/y/x"}, "/z/y/x", "/:a..."])
|
||||||
})
|
})
|
||||||
|
|
||||||
o("handles dynamically added out of order routes", function() {
|
o("handles dynamically added out of order routes", function() {
|
||||||
var routes = {}
|
var routes = {}
|
||||||
routes["/z/y/x"] = {data: 1}
|
routes["/z/y/x"] = {data: 1}
|
||||||
routes["/:a..."] = {data: 2}
|
routes["/:a..."] = {data: 2}
|
||||||
|
|
||||||
$window.location.href = prefix + "/z/y/x"
|
$window.location.href = prefix + "/z/y/x"
|
||||||
router.defineRoutes(routes, onRouteChange, onFail)
|
router.defineRoutes(routes, onRouteChange, onFail)
|
||||||
|
|
||||||
o(onRouteChange.callCount).equals(1)
|
o(onRouteChange.callCount).equals(1)
|
||||||
o(onRouteChange.args).deepEquals([{data: 1}, {}, "/z/y/x", "/z/y/x"])
|
o(onRouteChange.args).deepEquals([{data: 1}, {}, "/z/y/x", "/z/y/x"])
|
||||||
})
|
})
|
||||||
|
|
||||||
o("handles reversed dynamically added out of order routes", function() {
|
o("handles reversed dynamically added out of order routes", function() {
|
||||||
var routes = {}
|
var routes = {}
|
||||||
routes["/:a..."] = {data: 2}
|
routes["/:a..."] = {data: 2}
|
||||||
routes["/z/y/x"] = {data: 1}
|
routes["/z/y/x"] = {data: 1}
|
||||||
|
|
||||||
$window.location.href = prefix + "/z/y/x"
|
$window.location.href = prefix + "/z/y/x"
|
||||||
router.defineRoutes(routes, onRouteChange, onFail)
|
router.defineRoutes(routes, onRouteChange, onFail)
|
||||||
|
|
||||||
o(onRouteChange.callCount).equals(1)
|
o(onRouteChange.callCount).equals(1)
|
||||||
o(onRouteChange.args).deepEquals([{data: 2}, {a: "z/y/x"}, "/z/y/x", "/:a..."])
|
o(onRouteChange.args).deepEquals([{data: 2}, {a: "z/y/x"}, "/z/y/x", "/:a..."])
|
||||||
})
|
})
|
||||||
|
|
||||||
o("handles mixed out of order routes", function() {
|
o("handles mixed out of order routes", function() {
|
||||||
var routes = {"/z/y/x": {data: 1}}
|
var routes = {"/z/y/x": {data: 1}}
|
||||||
routes["/:a..."] = {data: 2}
|
routes["/:a..."] = {data: 2}
|
||||||
|
|
||||||
$window.location.href = prefix + "/z/y/x"
|
$window.location.href = prefix + "/z/y/x"
|
||||||
router.defineRoutes(routes, onRouteChange, onFail)
|
router.defineRoutes(routes, onRouteChange, onFail)
|
||||||
|
|
||||||
o(onRouteChange.callCount).equals(1)
|
o(onRouteChange.callCount).equals(1)
|
||||||
o(onRouteChange.args).deepEquals([{data: 1}, {}, "/z/y/x", "/z/y/x"])
|
o(onRouteChange.args).deepEquals([{data: 1}, {}, "/z/y/x", "/z/y/x"])
|
||||||
})
|
})
|
||||||
|
|
||||||
o("handles reverse mixed out of order routes", function() {
|
o("handles reverse mixed out of order routes", function() {
|
||||||
var routes = {"/:a...": {data: 2}}
|
var routes = {"/:a...": {data: 2}}
|
||||||
routes["/z/y/x"] = {data: 12}
|
routes["/z/y/x"] = {data: 12}
|
||||||
|
|
||||||
$window.location.href = prefix + "/z/y/x"
|
$window.location.href = prefix + "/z/y/x"
|
||||||
router.defineRoutes(routes, onRouteChange, onFail)
|
router.defineRoutes(routes, onRouteChange, onFail)
|
||||||
|
|
||||||
o(onRouteChange.callCount).equals(1)
|
o(onRouteChange.callCount).equals(1)
|
||||||
o(onRouteChange.args).deepEquals([{data: 2}, {a: "z/y/x"}, "/z/y/x", "/:a..."])
|
o(onRouteChange.args).deepEquals([{data: 2}, {a: "z/y/x"}, "/z/y/x", "/:a..."])
|
||||||
})
|
})
|
||||||
|
|
||||||
o("handles non-ascii routes", function() {
|
o("handles non-ascii routes", function() {
|
||||||
$window.location.href = prefix + "/ö"
|
$window.location.href = prefix + "/ö"
|
||||||
router.defineRoutes({"/ö": "aaa"}, onRouteChange, onFail)
|
router.defineRoutes({"/ö": "aaa"}, onRouteChange, onFail)
|
||||||
|
|
||||||
o(onRouteChange.callCount).equals(1)
|
o(onRouteChange.callCount).equals(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
o("replays", function() {
|
o("replays", function() {
|
||||||
$window.location.href = prefix + "/test"
|
$window.location.href = prefix + "/test"
|
||||||
var replay = router.defineRoutes({"/test": {data: 1}}, onRouteChange, onFail)
|
var replay = router.defineRoutes({"/test": {data: 1}}, onRouteChange, onFail)
|
||||||
replay()
|
replay()
|
||||||
|
|
||||||
o(onRouteChange.callCount).equals(2)
|
o(onRouteChange.callCount).equals(2)
|
||||||
o(onRouteChange.args).deepEquals([{data: 1}, {}, "/test", "/test"])
|
o(onRouteChange.args).deepEquals([{data: 1}, {}, "/test", "/test"])
|
||||||
o(onFail.callCount).equals(0)
|
o(onFail.callCount).equals(0)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ o.spec("Router.getPath", function() {
|
||||||
void ["#", "?", "", "#!", "?!", '/foo'].forEach(function(prefix) {
|
void ["#", "?", "", "#!", "?!", '/foo'].forEach(function(prefix) {
|
||||||
o.spec("using prefix `" + prefix + "`", function() {
|
o.spec("using prefix `" + prefix + "`", function() {
|
||||||
var $window, router, onRouteChange, onFail
|
var $window, router, onRouteChange, onFail
|
||||||
|
|
||||||
o.beforeEach(function() {
|
o.beforeEach(function() {
|
||||||
$window = pushStateMock()
|
$window = pushStateMock()
|
||||||
router = new Router($window)
|
router = new Router($window)
|
||||||
|
|
@ -16,31 +16,31 @@ o.spec("Router.getPath", function() {
|
||||||
onRouteChange = o.spy()
|
onRouteChange = o.spy()
|
||||||
onFail = o.spy()
|
onFail = o.spy()
|
||||||
})
|
})
|
||||||
|
|
||||||
o("gets route", function() {
|
o("gets route", function() {
|
||||||
$window.location.href = prefix + "/test"
|
$window.location.href = prefix + "/test"
|
||||||
router.defineRoutes({"/test": {data: 1}}, onRouteChange, onFail)
|
router.defineRoutes({"/test": {data: 1}}, onRouteChange, onFail)
|
||||||
|
|
||||||
o(router.getPath()).equals("/test")
|
o(router.getPath()).equals("/test")
|
||||||
})
|
})
|
||||||
o("gets route w/ params", function() {
|
o("gets route w/ params", function() {
|
||||||
$window.location.href = prefix + "/other/x/y/z?c=d#e=f"
|
$window.location.href = prefix + "/other/x/y/z?c=d#e=f"
|
||||||
router.defineRoutes({"/test": {data: 1}, "/other/:a/:b...": {data: 2}}, onRouteChange, onFail)
|
router.defineRoutes({"/test": {data: 1}, "/other/:a/:b...": {data: 2}}, onRouteChange, onFail)
|
||||||
|
|
||||||
o(router.getPath()).equals("/other/x/y/z?c=d#e=f")
|
o(router.getPath()).equals("/other/x/y/z?c=d#e=f")
|
||||||
})
|
})
|
||||||
o("gets route w/ escaped unicode", function() {
|
o("gets route w/ escaped unicode", function() {
|
||||||
$window.location.href = prefix + "/%C3%B6?%C3%B6=%C3%B6#%C3%B6=%C3%B6"
|
$window.location.href = prefix + "/%C3%B6?%C3%B6=%C3%B6#%C3%B6=%C3%B6"
|
||||||
router.defineRoutes({"/test": {data: 1}, "/ö/:a/:b...": {data: 2}}, onRouteChange, onFail)
|
router.defineRoutes({"/test": {data: 1}, "/ö/:a/:b...": {data: 2}}, onRouteChange, onFail)
|
||||||
|
|
||||||
o(router.getPath()).equals("/ö?ö=ö#ö=ö")
|
o(router.getPath()).equals("/ö?ö=ö#ö=ö")
|
||||||
})
|
})
|
||||||
o("gets route w/ unicode", function() {
|
o("gets route w/ unicode", function() {
|
||||||
$window.location.href = prefix + "/ö?ö=ö#ö=ö"
|
$window.location.href = prefix + "/ö?ö=ö#ö=ö"
|
||||||
router.defineRoutes({"/test": {data: 1}, "/ö/:a/:b...": {data: 2}}, onRouteChange, onFail)
|
router.defineRoutes({"/test": {data: 1}, "/ö/:a/:b...": {data: 2}}, onRouteChange, onFail)
|
||||||
|
|
||||||
o(router.getPath()).equals("/ö?ö=ö#ö=ö")
|
o(router.getPath()).equals("/ö?ö=ö#ö=ö")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ o.spec("Router.setPath", function() {
|
||||||
void ["#", "?", "", "#!", "?!", "/foo"].forEach(function(prefix) {
|
void ["#", "?", "", "#!", "?!", "/foo"].forEach(function(prefix) {
|
||||||
o.spec("using prefix `" + prefix + "`", function() {
|
o.spec("using prefix `" + prefix + "`", function() {
|
||||||
var $window, router, onRouteChange, onFail
|
var $window, router, onRouteChange, onFail
|
||||||
|
|
||||||
o.beforeEach(function() {
|
o.beforeEach(function() {
|
||||||
$window = pushStateMock()
|
$window = pushStateMock()
|
||||||
router = new Router($window)
|
router = new Router($window)
|
||||||
|
|
@ -16,38 +16,38 @@ o.spec("Router.setPath", function() {
|
||||||
onRouteChange = o.spy()
|
onRouteChange = o.spy()
|
||||||
onFail = o.spy()
|
onFail = o.spy()
|
||||||
})
|
})
|
||||||
|
|
||||||
o("sets route via API", function() {
|
o("sets route via API", function() {
|
||||||
$window.location.href = prefix + "/test"
|
$window.location.href = prefix + "/test"
|
||||||
router.defineRoutes({"/test": {data: 1}, "/other/:a/:b...": {data: 2}}, onRouteChange, onFail)
|
router.defineRoutes({"/test": {data: 1}, "/other/:a/:b...": {data: 2}}, onRouteChange, onFail)
|
||||||
router.setPath("/other/x/y/z?c=d#e=f")
|
router.setPath("/other/x/y/z?c=d#e=f")
|
||||||
|
|
||||||
o(router.getPath()).equals("/other/x/y/z?c=d#e=f")
|
o(router.getPath()).equals("/other/x/y/z?c=d#e=f")
|
||||||
})
|
})
|
||||||
o("sets route w/ escaped unicode", function() {
|
o("sets route w/ escaped unicode", function() {
|
||||||
$window.location.href = prefix + "/test"
|
$window.location.href = prefix + "/test"
|
||||||
router.defineRoutes({"/test": {data: 1}, "/ö/:a/:b...": {data: 2}}, onRouteChange, onFail)
|
router.defineRoutes({"/test": {data: 1}, "/ö/:a/:b...": {data: 2}}, onRouteChange, onFail)
|
||||||
router.setPath("/%C3%B6?%C3%B6=%C3%B6#%C3%B6=%C3%B6")
|
router.setPath("/%C3%B6?%C3%B6=%C3%B6#%C3%B6=%C3%B6")
|
||||||
|
|
||||||
o(router.getPath()).equals("/ö?ö=ö#ö=ö")
|
o(router.getPath()).equals("/ö?ö=ö#ö=ö")
|
||||||
})
|
})
|
||||||
o("sets route w/ unicode", function() {
|
o("sets route w/ unicode", function() {
|
||||||
$window.location.href = prefix + "/test"
|
$window.location.href = prefix + "/test"
|
||||||
router.defineRoutes({"/test": {data: 1}, "/ö/:a/:b...": {data: 2}}, onRouteChange, onFail)
|
router.defineRoutes({"/test": {data: 1}, "/ö/:a/:b...": {data: 2}}, onRouteChange, onFail)
|
||||||
router.setPath("/ö?ö=ö#ö=ö")
|
router.setPath("/ö?ö=ö#ö=ö")
|
||||||
|
|
||||||
o(router.getPath()).equals("/ö?ö=ö#ö=ö")
|
o(router.getPath()).equals("/ö?ö=ö#ö=ö")
|
||||||
})
|
})
|
||||||
|
|
||||||
o("sets route on fallback mode", function() {
|
o("sets route on fallback mode", function() {
|
||||||
$window.location.href = "file://" + prefix + "/test"
|
$window.location.href = "file://" + prefix + "/test"
|
||||||
|
|
||||||
router = new Router($window)
|
router = new Router($window)
|
||||||
router.setPrefix(prefix)
|
router.setPrefix(prefix)
|
||||||
|
|
||||||
router.defineRoutes({"/test": {data: 1}, "/other/:a/:b...": {data: 2}}, onRouteChange, onFail)
|
router.defineRoutes({"/test": {data: 1}, "/other/:a/:b...": {data: 2}}, onRouteChange, onFail)
|
||||||
router.setPath("/other/x/y/z?c=d#e=f")
|
router.setPath("/other/x/y/z?c=d#e=f")
|
||||||
|
|
||||||
o(router.getPath()).equals("/other/x/y/z?c=d#e=f")
|
o(router.getPath()).equals("/other/x/y/z?c=d#e=f")
|
||||||
})
|
})
|
||||||
o("sets route via pushState/onpopstate", function() {
|
o("sets route via pushState/onpopstate", function() {
|
||||||
|
|
@ -55,14 +55,14 @@ o.spec("Router.setPath", function() {
|
||||||
router.defineRoutes({"/test": {data: 1}, "/other/:a/:b...": {data: 2}}, onRouteChange, onFail)
|
router.defineRoutes({"/test": {data: 1}, "/other/:a/:b...": {data: 2}}, onRouteChange, onFail)
|
||||||
$window.history.pushState(null, null, prefix + "/other/x/y/z?c=d#e=f")
|
$window.history.pushState(null, null, prefix + "/other/x/y/z?c=d#e=f")
|
||||||
$window.onpopstate()
|
$window.onpopstate()
|
||||||
|
|
||||||
o(router.getPath()).equals("/other/x/y/z?c=d#e=f")
|
o(router.getPath()).equals("/other/x/y/z?c=d#e=f")
|
||||||
})
|
})
|
||||||
o("sets parameterized route", function() {
|
o("sets parameterized route", function() {
|
||||||
$window.location.href = prefix + "/test"
|
$window.location.href = prefix + "/test"
|
||||||
router.defineRoutes({"/test": {data: 1}, "/other/:a/:b...": {data: 2}}, onRouteChange, onFail)
|
router.defineRoutes({"/test": {data: 1}, "/other/:a/:b...": {data: 2}}, onRouteChange, onFail)
|
||||||
router.setPath("/other/:a/:b", {a: "x", b: "y/z", c: "d", e: "f"})
|
router.setPath("/other/:a/:b", {a: "x", b: "y/z", c: "d", e: "f"})
|
||||||
|
|
||||||
o(router.getPath()).equals("/other/x/y/z?c=d&e=f")
|
o(router.getPath()).equals("/other/x/y/z?c=d&e=f")
|
||||||
})
|
})
|
||||||
o("replace:true works", function() {
|
o("replace:true works", function() {
|
||||||
|
|
@ -70,7 +70,7 @@ o.spec("Router.setPath", function() {
|
||||||
router.defineRoutes({"/test": {data: 1}, "/other": {data: 2}}, onRouteChange, onFail)
|
router.defineRoutes({"/test": {data: 1}, "/other": {data: 2}}, onRouteChange, onFail)
|
||||||
router.setPath("/other", null, {replace: true})
|
router.setPath("/other", null, {replace: true})
|
||||||
$window.history.back()
|
$window.history.back()
|
||||||
|
|
||||||
o($window.location.href).equals("http://localhost/")
|
o($window.location.href).equals("http://localhost/")
|
||||||
})
|
})
|
||||||
o("replace:false works", function() {
|
o("replace:false works", function() {
|
||||||
|
|
@ -85,4 +85,4 @@ o.spec("Router.setPath", function() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -9,4 +9,4 @@ License: MIT
|
||||||
|
|
||||||
- pushStateMock - mock for `history.pushState` and `location`
|
- pushStateMock - mock for `history.pushState` and `location`
|
||||||
- ajaxMock - mock for XMLHttpRequest and JSONP transporters
|
- ajaxMock - mock for XMLHttpRequest and JSONP transporters
|
||||||
- parseURL - helper function for URL parsing
|
- parseURL - helper function for URL parsing
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
"use strict"
|
"use strict"
|
||||||
|
|
||||||
module.exports = typeof setImmediate === "function" ? setImmediate : setTimeout
|
module.exports = typeof setImmediate === "function" ? setImmediate : setTimeout
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,9 @@ module.exports = function() {
|
||||||
var ancestor = this
|
var ancestor = this
|
||||||
while (ancestor !== child && ancestor !== null) ancestor = ancestor.parentNode
|
while (ancestor !== child && ancestor !== null) ancestor = ancestor.parentNode
|
||||||
if (ancestor === child) throw new Error("Node cannot be inserted at the specified point in the hierarchy")
|
if (ancestor === child) throw new Error("Node cannot be inserted at the specified point in the hierarchy")
|
||||||
|
|
||||||
if (child.nodeType == null) throw new Error("Argument is not a DOM element")
|
if (child.nodeType == null) throw new Error("Argument is not a DOM element")
|
||||||
|
|
||||||
var index = this.childNodes.indexOf(child)
|
var index = this.childNodes.indexOf(child)
|
||||||
if (index > -1) this.childNodes.splice(index, 1)
|
if (index > -1) this.childNodes.splice(index, 1)
|
||||||
if (child.nodeType === 11) {
|
if (child.nodeType === 11) {
|
||||||
|
|
@ -35,9 +35,9 @@ module.exports = function() {
|
||||||
var ancestor = this
|
var ancestor = this
|
||||||
while (ancestor !== child && ancestor !== null) ancestor = ancestor.parentNode
|
while (ancestor !== child && ancestor !== null) ancestor = ancestor.parentNode
|
||||||
if (ancestor === child) throw new Error("Node cannot be inserted at the specified point in the hierarchy")
|
if (ancestor === child) throw new Error("Node cannot be inserted at the specified point in the hierarchy")
|
||||||
|
|
||||||
if (child.nodeType == null) throw new Error("Argument is not a DOM element")
|
if (child.nodeType == null) throw new Error("Argument is not a DOM element")
|
||||||
|
|
||||||
var refIndex = this.childNodes.indexOf(reference)
|
var refIndex = this.childNodes.indexOf(reference)
|
||||||
var index = this.childNodes.indexOf(child)
|
var index = this.childNodes.indexOf(child)
|
||||||
if (reference !== null && refIndex < 0) throw new TypeError("Invalid argument")
|
if (reference !== null && refIndex < 0) throw new TypeError("Invalid argument")
|
||||||
|
|
@ -109,7 +109,7 @@ module.exports = function() {
|
||||||
},
|
},
|
||||||
set innerHTML(value) {
|
set innerHTML(value) {
|
||||||
while (this.firstChild) this.removeChild(this.firstChild)
|
while (this.firstChild) this.removeChild(this.firstChild)
|
||||||
|
|
||||||
var stack = [this], depth = 0, voidElements = ["area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"]
|
var stack = [this], depth = 0, voidElements = ["area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"]
|
||||||
value.replace(/<([a-z0-9\-]+?)((?:\s+?[^=]+?=(?:"[^"]*?"|'[^']*?'|[^\s>]*))*?)(\s*\/)?>|<\/([a-z0-9\-]+?)>|([^<]+)/g, function(match, startTag, attrs, selfClosed, endTag, text) {
|
value.replace(/<([a-z0-9\-]+?)((?:\s+?[^=]+?=(?:"[^"]*?"|'[^']*?'|[^\s>]*))*?)(\s*\/)?>|<\/([a-z0-9\-]+?)>|([^<]+)/g, function(match, startTag, attrs, selfClosed, endTag, text) {
|
||||||
if (startTag) {
|
if (startTag) {
|
||||||
|
|
@ -173,7 +173,7 @@ module.exports = function() {
|
||||||
if (this.nodeName === "INPUT" && this.attributes["type"] != null && this.attributes["type"].nodeValue === "checkbox" && e.type === "click") {
|
if (this.nodeName === "INPUT" && this.attributes["type"] != null && this.attributes["type"].nodeValue === "checkbox" && e.type === "click") {
|
||||||
this.checked = !this.checked
|
this.checked = !this.checked
|
||||||
}
|
}
|
||||||
|
|
||||||
e.target = this
|
e.target = this
|
||||||
if (events[e.type] != null) {
|
if (events[e.type] != null) {
|
||||||
for (var i = 0; i < events[e.type].length; i++) {
|
for (var i = 0; i < events[e.type].length; i++) {
|
||||||
|
|
@ -186,7 +186,7 @@ module.exports = function() {
|
||||||
if (typeof this["on" + e.type] === "function" && !isModernEvent(e.type)) this["on" + e.type](e)
|
if (typeof this["on" + e.type] === "function" && !isModernEvent(e.type)) this["on" + e.type](e)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element.nodeName === "A") {
|
if (element.nodeName === "A") {
|
||||||
var href
|
var href
|
||||||
Object.defineProperty(element, "href", {
|
Object.defineProperty(element, "href", {
|
||||||
|
|
@ -195,7 +195,7 @@ module.exports = function() {
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element.nodeName === "INPUT") {
|
if (element.nodeName === "INPUT") {
|
||||||
var checked
|
var checked
|
||||||
Object.defineProperty(element, "checked", {
|
Object.defineProperty(element, "checked", {
|
||||||
|
|
@ -203,10 +203,10 @@ module.exports = function() {
|
||||||
set: function(value) {checked = Boolean(value)},
|
set: function(value) {checked = Boolean(value)},
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
element.value = ""
|
element.value = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element.nodeName === "TEXTAREA") {
|
if (element.nodeName === "TEXTAREA") {
|
||||||
var value
|
var value
|
||||||
Object.defineProperty(element, "value", {
|
Object.defineProperty(element, "value", {
|
||||||
|
|
@ -218,7 +218,7 @@ module.exports = function() {
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function getOptions(element) {
|
function getOptions(element) {
|
||||||
var options = []
|
var options = []
|
||||||
for (var i = 0; i < element.childNodes.length; i++) {
|
for (var i = 0; i < element.childNodes.length; i++) {
|
||||||
|
|
@ -340,6 +340,6 @@ module.exports = function() {
|
||||||
$window.document.body = $window.document.createElement("body")
|
$window.document.body = $window.document.createElement("body")
|
||||||
$window.document.documentElement.appendChild($window.document.body)
|
$window.document.documentElement.appendChild($window.document.body)
|
||||||
activeElement = $window.document.body
|
activeElement = $window.document.body
|
||||||
|
|
||||||
return $window
|
return $window
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,9 @@ module.exports = function() {
|
||||||
var pathname = "/"
|
var pathname = "/"
|
||||||
var search = ""
|
var search = ""
|
||||||
var hash = ""
|
var hash = ""
|
||||||
|
|
||||||
var past = [], future = []
|
var past = [], future = []
|
||||||
|
|
||||||
function getURL() {
|
function getURL() {
|
||||||
if (protocol === "file:") return protocol + "//" + pathname + search + hash
|
if (protocol === "file:") return protocol + "//" + pathname + search + hash
|
||||||
return protocol + "//" + hostname + prefix(":", port) + pathname + search + hash
|
return protocol + "//" + hostname + prefix(":", port) + pathname + search + hash
|
||||||
|
|
@ -75,7 +75,7 @@ module.exports = function() {
|
||||||
get href() {
|
get href() {
|
||||||
return getURL()
|
return getURL()
|
||||||
},
|
},
|
||||||
|
|
||||||
set protocol(value) {
|
set protocol(value) {
|
||||||
throw new Error("Protocol is read-only")
|
throw new Error("Protocol is read-only")
|
||||||
},
|
},
|
||||||
|
|
@ -112,7 +112,7 @@ module.exports = function() {
|
||||||
hash = prefix("#", value)
|
hash = prefix("#", value)
|
||||||
if (oldHash != hash) hashchange()
|
if (oldHash != hash) hashchange()
|
||||||
},
|
},
|
||||||
|
|
||||||
set origin(value) {
|
set origin(value) {
|
||||||
//origin is writable but ignored
|
//origin is writable but ignored
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
<script src="test-pushStateMock.js"></script>
|
<script src="test-pushStateMock.js"></script>
|
||||||
<script src="test-xhrMock.js"></script>
|
<script src="test-xhrMock.js"></script>
|
||||||
<script src="test-domMock.js"></script>
|
<script src="test-domMock.js"></script>
|
||||||
|
|
||||||
<script>require("../../ospec/ospec").run()</script>
|
<script>require("../../ospec/ospec").run()</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,11 @@ o.spec("domMock", function() {
|
||||||
o.beforeEach(function() {
|
o.beforeEach(function() {
|
||||||
$document = domMock().document
|
$document = domMock().document
|
||||||
})
|
})
|
||||||
|
|
||||||
o.spec("createElement", function() {
|
o.spec("createElement", function() {
|
||||||
o("works", function() {
|
o("works", function() {
|
||||||
var node = $document.createElement("div")
|
var node = $document.createElement("div")
|
||||||
|
|
||||||
o(node.nodeType).equals(1)
|
o(node.nodeType).equals(1)
|
||||||
o(node.nodeName).equals("DIV")
|
o(node.nodeName).equals("DIV")
|
||||||
o(node.namespaceURI).equals("http://www.w3.org/1999/xhtml")
|
o(node.namespaceURI).equals("http://www.w3.org/1999/xhtml")
|
||||||
|
|
@ -22,11 +22,11 @@ o.spec("domMock", function() {
|
||||||
o(node.nextSibling).equals(null)
|
o(node.nextSibling).equals(null)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
o.spec("createElementNS", function() {
|
o.spec("createElementNS", function() {
|
||||||
o("works", function() {
|
o("works", function() {
|
||||||
var node = $document.createElementNS("http://www.w3.org/2000/svg", "svg")
|
var node = $document.createElementNS("http://www.w3.org/2000/svg", "svg")
|
||||||
|
|
||||||
o(node.nodeType).equals(1)
|
o(node.nodeType).equals(1)
|
||||||
o(node.nodeName).equals("svg")
|
o(node.nodeName).equals("svg")
|
||||||
o(node.namespaceURI).equals("http://www.w3.org/2000/svg")
|
o(node.namespaceURI).equals("http://www.w3.org/2000/svg")
|
||||||
|
|
@ -36,11 +36,11 @@ o.spec("domMock", function() {
|
||||||
o(node.nextSibling).equals(null)
|
o(node.nextSibling).equals(null)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
o.spec("createTextNode", function() {
|
o.spec("createTextNode", function() {
|
||||||
o("works", function() {
|
o("works", function() {
|
||||||
var node = $document.createTextNode("abc")
|
var node = $document.createTextNode("abc")
|
||||||
|
|
||||||
o(node.nodeType).equals(3)
|
o(node.nodeType).equals(3)
|
||||||
o(node.nodeName).equals("#text")
|
o(node.nodeName).equals("#text")
|
||||||
o(node.parentNode).equals(null)
|
o(node.parentNode).equals(null)
|
||||||
|
|
@ -48,41 +48,41 @@ o.spec("domMock", function() {
|
||||||
})
|
})
|
||||||
o("works w/ number", function() {
|
o("works w/ number", function() {
|
||||||
var node = $document.createTextNode(123)
|
var node = $document.createTextNode(123)
|
||||||
|
|
||||||
o(node.nodeValue).equals("123")
|
o(node.nodeValue).equals("123")
|
||||||
})
|
})
|
||||||
o("works w/ null", function() {
|
o("works w/ null", function() {
|
||||||
var node = $document.createTextNode(null)
|
var node = $document.createTextNode(null)
|
||||||
|
|
||||||
o(node.nodeValue).equals("null")
|
o(node.nodeValue).equals("null")
|
||||||
})
|
})
|
||||||
o("works w/ undefined", function() {
|
o("works w/ undefined", function() {
|
||||||
var node = $document.createTextNode(undefined)
|
var node = $document.createTextNode(undefined)
|
||||||
|
|
||||||
o(node.nodeValue).equals("undefined")
|
o(node.nodeValue).equals("undefined")
|
||||||
})
|
})
|
||||||
o("works w/ object", function() {
|
o("works w/ object", function() {
|
||||||
var node = $document.createTextNode({})
|
var node = $document.createTextNode({})
|
||||||
|
|
||||||
o(node.nodeValue).equals("[object Object]")
|
o(node.nodeValue).equals("[object Object]")
|
||||||
})
|
})
|
||||||
o("does not unescape HTML", function() {
|
o("does not unescape HTML", function() {
|
||||||
var node = $document.createTextNode("<a>&</a>")
|
var node = $document.createTextNode("<a>&</a>")
|
||||||
|
|
||||||
o(node.nodeValue).equals("<a>&</a>")
|
o(node.nodeValue).equals("<a>&</a>")
|
||||||
})
|
})
|
||||||
o("nodeValue casts to string", function() {
|
o("nodeValue casts to string", function() {
|
||||||
var node = $document.createTextNode("a")
|
var node = $document.createTextNode("a")
|
||||||
node.nodeValue = true
|
node.nodeValue = true
|
||||||
|
|
||||||
o(node.nodeValue).equals("true")
|
o(node.nodeValue).equals("true")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
o.spec("createDocumentFragment", function() {
|
o.spec("createDocumentFragment", function() {
|
||||||
o("works", function() {
|
o("works", function() {
|
||||||
var node = $document.createDocumentFragment()
|
var node = $document.createDocumentFragment()
|
||||||
|
|
||||||
o(node.nodeType).equals(11)
|
o(node.nodeType).equals(11)
|
||||||
o(node.nodeName).equals("#document-fragment")
|
o(node.nodeName).equals("#document-fragment")
|
||||||
o(node.parentNode).equals(null)
|
o(node.parentNode).equals(null)
|
||||||
|
|
@ -90,13 +90,13 @@ o.spec("domMock", function() {
|
||||||
o(node.firstChild).equals(null)
|
o(node.firstChild).equals(null)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
o.spec("appendChild", function() {
|
o.spec("appendChild", function() {
|
||||||
o("works", function() {
|
o("works", function() {
|
||||||
var parent = $document.createElement("div")
|
var parent = $document.createElement("div")
|
||||||
var child = $document.createElement("a")
|
var child = $document.createElement("a")
|
||||||
parent.appendChild(child)
|
parent.appendChild(child)
|
||||||
|
|
||||||
o(parent.childNodes.length).equals(1)
|
o(parent.childNodes.length).equals(1)
|
||||||
o(parent.childNodes[0]).equals(child)
|
o(parent.childNodes[0]).equals(child)
|
||||||
o(parent.firstChild).equals(child)
|
o(parent.firstChild).equals(child)
|
||||||
|
|
@ -109,7 +109,7 @@ o.spec("domMock", function() {
|
||||||
parent.appendChild(a)
|
parent.appendChild(a)
|
||||||
parent.appendChild(b)
|
parent.appendChild(b)
|
||||||
parent.appendChild(a)
|
parent.appendChild(a)
|
||||||
|
|
||||||
o(parent.childNodes.length).equals(2)
|
o(parent.childNodes.length).equals(2)
|
||||||
o(parent.childNodes[0]).equals(b)
|
o(parent.childNodes[0]).equals(b)
|
||||||
o(parent.childNodes[1]).equals(a)
|
o(parent.childNodes[1]).equals(a)
|
||||||
|
|
@ -126,7 +126,7 @@ o.spec("domMock", function() {
|
||||||
parent.appendChild(a)
|
parent.appendChild(a)
|
||||||
source.appendChild(b)
|
source.appendChild(b)
|
||||||
parent.appendChild(b)
|
parent.appendChild(b)
|
||||||
|
|
||||||
o(source.childNodes.length).equals(0)
|
o(source.childNodes.length).equals(0)
|
||||||
})
|
})
|
||||||
o("transfers from fragment", function() {
|
o("transfers from fragment", function() {
|
||||||
|
|
@ -137,7 +137,7 @@ o.spec("domMock", function() {
|
||||||
a.appendChild(b)
|
a.appendChild(b)
|
||||||
a.appendChild(c)
|
a.appendChild(c)
|
||||||
parent.appendChild(a)
|
parent.appendChild(a)
|
||||||
|
|
||||||
o(parent.childNodes.length).equals(2)
|
o(parent.childNodes.length).equals(2)
|
||||||
o(parent.childNodes[0]).equals(b)
|
o(parent.childNodes[0]).equals(b)
|
||||||
o(parent.childNodes[1]).equals(c)
|
o(parent.childNodes[1]).equals(c)
|
||||||
|
|
@ -168,14 +168,14 @@ o.spec("domMock", function() {
|
||||||
catch (e) {done()}
|
catch (e) {done()}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
o.spec("removeChild", function() {
|
o.spec("removeChild", function() {
|
||||||
o("works", function() {
|
o("works", function() {
|
||||||
var parent = $document.createElement("div")
|
var parent = $document.createElement("div")
|
||||||
var child = $document.createElement("a")
|
var child = $document.createElement("a")
|
||||||
parent.appendChild(child)
|
parent.appendChild(child)
|
||||||
parent.removeChild(child)
|
parent.removeChild(child)
|
||||||
|
|
||||||
o(parent.childNodes.length).equals(0)
|
o(parent.childNodes.length).equals(0)
|
||||||
o(parent.firstChild).equals(null)
|
o(parent.firstChild).equals(null)
|
||||||
o(child.parentNode).equals(null)
|
o(child.parentNode).equals(null)
|
||||||
|
|
@ -187,7 +187,7 @@ o.spec("domMock", function() {
|
||||||
catch (e) {done()}
|
catch (e) {done()}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
o.spec("insertBefore", function() {
|
o.spec("insertBefore", function() {
|
||||||
o("works", function() {
|
o("works", function() {
|
||||||
var parent = $document.createElement("div")
|
var parent = $document.createElement("div")
|
||||||
|
|
@ -195,7 +195,7 @@ o.spec("domMock", function() {
|
||||||
var b = $document.createElement("b")
|
var b = $document.createElement("b")
|
||||||
parent.appendChild(a)
|
parent.appendChild(a)
|
||||||
parent.insertBefore(b, a)
|
parent.insertBefore(b, a)
|
||||||
|
|
||||||
o(parent.childNodes.length).equals(2)
|
o(parent.childNodes.length).equals(2)
|
||||||
o(parent.childNodes[0]).equals(b)
|
o(parent.childNodes[0]).equals(b)
|
||||||
o(parent.childNodes[1]).equals(a)
|
o(parent.childNodes[1]).equals(a)
|
||||||
|
|
@ -211,7 +211,7 @@ o.spec("domMock", function() {
|
||||||
parent.appendChild(a)
|
parent.appendChild(a)
|
||||||
parent.appendChild(b)
|
parent.appendChild(b)
|
||||||
parent.insertBefore(b, a)
|
parent.insertBefore(b, a)
|
||||||
|
|
||||||
o(parent.childNodes.length).equals(2)
|
o(parent.childNodes.length).equals(2)
|
||||||
o(parent.childNodes[0]).equals(b)
|
o(parent.childNodes[0]).equals(b)
|
||||||
o(parent.childNodes[1]).equals(a)
|
o(parent.childNodes[1]).equals(a)
|
||||||
|
|
@ -228,7 +228,7 @@ o.spec("domMock", function() {
|
||||||
parent.appendChild(a)
|
parent.appendChild(a)
|
||||||
source.appendChild(b)
|
source.appendChild(b)
|
||||||
parent.insertBefore(b, a)
|
parent.insertBefore(b, a)
|
||||||
|
|
||||||
o(source.childNodes.length).equals(0)
|
o(source.childNodes.length).equals(0)
|
||||||
})
|
})
|
||||||
o("transfers from fragment", function() {
|
o("transfers from fragment", function() {
|
||||||
|
|
@ -241,7 +241,7 @@ o.spec("domMock", function() {
|
||||||
a.appendChild(b)
|
a.appendChild(b)
|
||||||
a.appendChild(c)
|
a.appendChild(c)
|
||||||
parent.insertBefore(a, ref)
|
parent.insertBefore(a, ref)
|
||||||
|
|
||||||
o(parent.childNodes.length).equals(3)
|
o(parent.childNodes.length).equals(3)
|
||||||
o(parent.childNodes[0]).equals(b)
|
o(parent.childNodes[0]).equals(b)
|
||||||
o(parent.childNodes[1]).equals(c)
|
o(parent.childNodes[1]).equals(c)
|
||||||
|
|
@ -261,7 +261,7 @@ o.spec("domMock", function() {
|
||||||
var b = $document.createElement("b")
|
var b = $document.createElement("b")
|
||||||
parent.appendChild(a)
|
parent.appendChild(a)
|
||||||
parent.insertBefore(b, null)
|
parent.insertBefore(b, null)
|
||||||
|
|
||||||
o(parent.childNodes.length).equals(2)
|
o(parent.childNodes.length).equals(2)
|
||||||
o(parent.childNodes[0]).equals(a)
|
o(parent.childNodes[0]).equals(a)
|
||||||
o(parent.childNodes[1]).equals(b)
|
o(parent.childNodes[1]).equals(b)
|
||||||
|
|
@ -312,81 +312,81 @@ o.spec("domMock", function() {
|
||||||
catch (e) {done()}
|
catch (e) {done()}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
o.spec("setAttribute", function() {
|
o.spec("setAttribute", function() {
|
||||||
o("works", function() {
|
o("works", function() {
|
||||||
var div = $document.createElement("div")
|
var div = $document.createElement("div")
|
||||||
div.setAttribute("id", "aaa")
|
div.setAttribute("id", "aaa")
|
||||||
|
|
||||||
o(div.attributes["id"].nodeValue).equals("aaa")
|
o(div.attributes["id"].nodeValue).equals("aaa")
|
||||||
o(div.attributes["id"].namespaceURI).equals(null)
|
o(div.attributes["id"].namespaceURI).equals(null)
|
||||||
})
|
})
|
||||||
o("works w/ number", function() {
|
o("works w/ number", function() {
|
||||||
var div = $document.createElement("div")
|
var div = $document.createElement("div")
|
||||||
div.setAttribute("id", 123)
|
div.setAttribute("id", 123)
|
||||||
|
|
||||||
o(div.attributes["id"].nodeValue).equals("123")
|
o(div.attributes["id"].nodeValue).equals("123")
|
||||||
})
|
})
|
||||||
o("works w/ null", function() {
|
o("works w/ null", function() {
|
||||||
var div = $document.createElement("div")
|
var div = $document.createElement("div")
|
||||||
div.setAttribute("id", null)
|
div.setAttribute("id", null)
|
||||||
|
|
||||||
o(div.attributes["id"].nodeValue).equals("null")
|
o(div.attributes["id"].nodeValue).equals("null")
|
||||||
})
|
})
|
||||||
o("works w/ undefined", function() {
|
o("works w/ undefined", function() {
|
||||||
var div = $document.createElement("div")
|
var div = $document.createElement("div")
|
||||||
div.setAttribute("id", undefined)
|
div.setAttribute("id", undefined)
|
||||||
|
|
||||||
o(div.attributes["id"].nodeValue).equals("undefined")
|
o(div.attributes["id"].nodeValue).equals("undefined")
|
||||||
})
|
})
|
||||||
o("works w/ object", function() {
|
o("works w/ object", function() {
|
||||||
var div = $document.createElement("div")
|
var div = $document.createElement("div")
|
||||||
div.setAttribute("id", {})
|
div.setAttribute("id", {})
|
||||||
|
|
||||||
o(div.attributes["id"].nodeValue).equals("[object Object]")
|
o(div.attributes["id"].nodeValue).equals("[object Object]")
|
||||||
})
|
})
|
||||||
o("setting via attributes map stringifies", function() {
|
o("setting via attributes map stringifies", function() {
|
||||||
var div = $document.createElement("div")
|
var div = $document.createElement("div")
|
||||||
div.setAttribute("id", "a")
|
div.setAttribute("id", "a")
|
||||||
div.attributes["id"].nodeValue = 123
|
div.attributes["id"].nodeValue = 123
|
||||||
|
|
||||||
o(div.attributes["id"].nodeValue).equals("123")
|
o(div.attributes["id"].nodeValue).equals("123")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
o.spec("setAttributeNS", function() {
|
o.spec("setAttributeNS", function() {
|
||||||
o("works", function() {
|
o("works", function() {
|
||||||
var div = $document.createElement("div")
|
var div = $document.createElement("div")
|
||||||
div.setAttributeNS("http://www.w3.org/1999/xlink", "href", "aaa")
|
div.setAttributeNS("http://www.w3.org/1999/xlink", "href", "aaa")
|
||||||
|
|
||||||
o(div.attributes["href"].nodeValue).equals("aaa")
|
o(div.attributes["href"].nodeValue).equals("aaa")
|
||||||
o(div.attributes["href"].namespaceURI).equals("http://www.w3.org/1999/xlink")
|
o(div.attributes["href"].namespaceURI).equals("http://www.w3.org/1999/xlink")
|
||||||
})
|
})
|
||||||
o("works w/ number", function() {
|
o("works w/ number", function() {
|
||||||
var div = $document.createElement("div")
|
var div = $document.createElement("div")
|
||||||
div.setAttributeNS("http://www.w3.org/1999/xlink", "href", 123)
|
div.setAttributeNS("http://www.w3.org/1999/xlink", "href", 123)
|
||||||
|
|
||||||
o(div.attributes["href"].nodeValue).equals("123")
|
o(div.attributes["href"].nodeValue).equals("123")
|
||||||
o(div.attributes["href"].namespaceURI).equals("http://www.w3.org/1999/xlink")
|
o(div.attributes["href"].namespaceURI).equals("http://www.w3.org/1999/xlink")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
o.spec("removeAttribute", function() {
|
o.spec("removeAttribute", function() {
|
||||||
o("works", function() {
|
o("works", function() {
|
||||||
var div = $document.createElement("div")
|
var div = $document.createElement("div")
|
||||||
div.setAttribute("id", "aaa")
|
div.setAttribute("id", "aaa")
|
||||||
div.removeAttribute("id")
|
div.removeAttribute("id")
|
||||||
|
|
||||||
o("id" in div.attributes).equals(false)
|
o("id" in div.attributes).equals(false)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
o.spec("textContent", function() {
|
o.spec("textContent", function() {
|
||||||
o("works", function() {
|
o("works", function() {
|
||||||
var div = $document.createElement("div")
|
var div = $document.createElement("div")
|
||||||
var a = $document.createElement("a")
|
var a = $document.createElement("a")
|
||||||
div.textContent = "aaa"
|
div.textContent = "aaa"
|
||||||
|
|
||||||
o(div.childNodes.length).equals(1)
|
o(div.childNodes.length).equals(1)
|
||||||
o(div.firstChild.nodeType).equals(3)
|
o(div.firstChild.nodeType).equals(3)
|
||||||
o(div.firstChild.nodeValue).equals("aaa")
|
o(div.firstChild.nodeValue).equals("aaa")
|
||||||
|
|
@ -395,11 +395,11 @@ o.spec("domMock", function() {
|
||||||
var div = $document.createElement("div")
|
var div = $document.createElement("div")
|
||||||
var a = $document.createElement("a")
|
var a = $document.createElement("a")
|
||||||
div.textContent = ""
|
div.textContent = ""
|
||||||
|
|
||||||
o(div.childNodes.length).equals(0)
|
o(div.childNodes.length).equals(0)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
o.spec("innerHTML", function() {
|
o.spec("innerHTML", function() {
|
||||||
o("works", function() {
|
o("works", function() {
|
||||||
var div = $document.createElement("div")
|
var div = $document.createElement("div")
|
||||||
|
|
@ -446,7 +446,7 @@ o.spec("domMock", function() {
|
||||||
var a = $document.createElement("a")
|
var a = $document.createElement("a")
|
||||||
div.appendChild(a)
|
div.appendChild(a)
|
||||||
div.innerHTML = "<b></b>"
|
div.innerHTML = "<b></b>"
|
||||||
|
|
||||||
o(a.parentNode).equals(null)
|
o(a.parentNode).equals(null)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
@ -462,22 +462,22 @@ o.spec("domMock", function() {
|
||||||
var input = $document.createElement("input")
|
var input = $document.createElement("input")
|
||||||
$document.body.appendChild(input)
|
$document.body.appendChild(input)
|
||||||
input.focus()
|
input.focus()
|
||||||
|
|
||||||
o($document.activeElement).equals(input)
|
o($document.activeElement).equals(input)
|
||||||
|
|
||||||
$document.body.removeChild(input)
|
$document.body.removeChild(input)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
o.spec("style", function() {
|
o.spec("style", function() {
|
||||||
o("has style property", function() {
|
o("has style property", function() {
|
||||||
var div = $document.createElement("div")
|
var div = $document.createElement("div")
|
||||||
|
|
||||||
o(typeof div.style).equals("object")
|
o(typeof div.style).equals("object")
|
||||||
})
|
})
|
||||||
o("setting style string works", function() {
|
o("setting style string works", function() {
|
||||||
var div = $document.createElement("div")
|
var div = $document.createElement("div")
|
||||||
div.style = "background-color: red; border-bottom: 1px solid red;"
|
div.style = "background-color: red; border-bottom: 1px solid red;"
|
||||||
|
|
||||||
o(div.style.backgroundColor).equals("red")
|
o(div.style.backgroundColor).equals("red")
|
||||||
o(div.style.borderBottom).equals("1px solid red")
|
o(div.style.borderBottom).equals("1px solid red")
|
||||||
})
|
})
|
||||||
|
|
@ -485,7 +485,7 @@ o.spec("domMock", function() {
|
||||||
var div = $document.createElement("div")
|
var div = $document.createElement("div")
|
||||||
div.style = "background: red;"
|
div.style = "background: red;"
|
||||||
div.style = ""
|
div.style = ""
|
||||||
|
|
||||||
o(div.style.background).equals("")
|
o(div.style.background).equals("")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
@ -497,17 +497,17 @@ o.spec("domMock", function() {
|
||||||
div = $document.createElement("div")
|
div = $document.createElement("div")
|
||||||
e = $document.createEvent("MouseEvents")
|
e = $document.createEvent("MouseEvents")
|
||||||
e.initEvent("click", true, true)
|
e.initEvent("click", true, true)
|
||||||
|
|
||||||
$document.body.appendChild(div)
|
$document.body.appendChild(div)
|
||||||
})
|
})
|
||||||
o.afterEach(function() {
|
o.afterEach(function() {
|
||||||
$document.body.removeChild(div)
|
$document.body.removeChild(div)
|
||||||
})
|
})
|
||||||
|
|
||||||
o("addEventListener works", function() {
|
o("addEventListener works", function() {
|
||||||
div.addEventListener("click", spy, false)
|
div.addEventListener("click", spy, false)
|
||||||
div.dispatchEvent(e)
|
div.dispatchEvent(e)
|
||||||
|
|
||||||
o(spy.callCount).equals(1)
|
o(spy.callCount).equals(1)
|
||||||
o(spy.this).equals(div)
|
o(spy.this).equals(div)
|
||||||
o(spy.args[0].type).equals("click")
|
o(spy.args[0].type).equals("click")
|
||||||
|
|
@ -517,14 +517,14 @@ o.spec("domMock", function() {
|
||||||
div.addEventListener("click", spy, false)
|
div.addEventListener("click", spy, false)
|
||||||
div.removeEventListener("click", spy, false)
|
div.removeEventListener("click", spy, false)
|
||||||
div.dispatchEvent(e)
|
div.dispatchEvent(e)
|
||||||
|
|
||||||
o(spy.callCount).equals(0)
|
o(spy.callCount).equals(0)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
o("click fires onclick", function() {
|
o("click fires onclick", function() {
|
||||||
div.onclick = spy
|
div.onclick = spy
|
||||||
div.dispatchEvent(e)
|
div.dispatchEvent(e)
|
||||||
|
|
||||||
o(spy.callCount).equals(1)
|
o(spy.callCount).equals(1)
|
||||||
o(spy.this).equals(div)
|
o(spy.this).equals(div)
|
||||||
o(spy.args[0].type).equals("click")
|
o(spy.args[0].type).equals("click")
|
||||||
|
|
@ -542,17 +542,17 @@ o.spec("domMock", function() {
|
||||||
div = $document.createElement("div")
|
div = $document.createElement("div")
|
||||||
e = $document.createEvent("HTMLEvents")
|
e = $document.createEvent("HTMLEvents")
|
||||||
e.initEvent("transitionend", true, true)
|
e.initEvent("transitionend", true, true)
|
||||||
|
|
||||||
$document.body.appendChild(div)
|
$document.body.appendChild(div)
|
||||||
})
|
})
|
||||||
o.afterEach(function() {
|
o.afterEach(function() {
|
||||||
$document.body.removeChild(div)
|
$document.body.removeChild(div)
|
||||||
})
|
})
|
||||||
|
|
||||||
o("ontransitionend does not fire", function(done) {
|
o("ontransitionend does not fire", function(done) {
|
||||||
div.ontransitionend = spy
|
div.ontransitionend = spy
|
||||||
div.dispatchEvent(e)
|
div.dispatchEvent(e)
|
||||||
|
|
||||||
o(spy.callCount).equals(0)
|
o(spy.callCount).equals(0)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
|
@ -562,21 +562,21 @@ o.spec("domMock", function() {
|
||||||
o.spec("a[href]", function() {
|
o.spec("a[href]", function() {
|
||||||
o("is empty string if no attribute", function() {
|
o("is empty string if no attribute", function() {
|
||||||
var a = $document.createElement("a")
|
var a = $document.createElement("a")
|
||||||
|
|
||||||
o(a.href).equals("")
|
o(a.href).equals("")
|
||||||
o(a.attributes["href"]).equals(undefined)
|
o(a.attributes["href"]).equals(undefined)
|
||||||
})
|
})
|
||||||
o("is path if attribute is set", function() {
|
o("is path if attribute is set", function() {
|
||||||
var a = $document.createElement("a")
|
var a = $document.createElement("a")
|
||||||
a.setAttribute("href", "")
|
a.setAttribute("href", "")
|
||||||
|
|
||||||
o(a.href).notEquals("")
|
o(a.href).notEquals("")
|
||||||
o(a.attributes["href"].nodeValue).equals("")
|
o(a.attributes["href"].nodeValue).equals("")
|
||||||
})
|
})
|
||||||
o("is path if property is set", function() {
|
o("is path if property is set", function() {
|
||||||
var a = $document.createElement("a")
|
var a = $document.createElement("a")
|
||||||
a.href = ""
|
a.href = ""
|
||||||
|
|
||||||
o(a.href).notEquals("")
|
o(a.href).notEquals("")
|
||||||
o(a.attributes["href"].nodeValue).equals("")
|
o(a.attributes["href"].nodeValue).equals("")
|
||||||
})
|
})
|
||||||
|
|
@ -585,24 +585,24 @@ o.spec("domMock", function() {
|
||||||
o("only exists in input elements", function() {
|
o("only exists in input elements", function() {
|
||||||
var input = $document.createElement("input")
|
var input = $document.createElement("input")
|
||||||
var a = $document.createElement("a")
|
var a = $document.createElement("a")
|
||||||
|
|
||||||
o("checked" in input).equals(true)
|
o("checked" in input).equals(true)
|
||||||
o("checked" in a).equals(false)
|
o("checked" in a).equals(false)
|
||||||
})
|
})
|
||||||
o("tracks attribute value when unset", function() {
|
o("tracks attribute value when unset", function() {
|
||||||
var input = $document.createElement("input")
|
var input = $document.createElement("input")
|
||||||
input.setAttribute("type", "checkbox")
|
input.setAttribute("type", "checkbox")
|
||||||
|
|
||||||
o(input.checked).equals(false)
|
o(input.checked).equals(false)
|
||||||
o(input.attributes["checked"]).equals(undefined)
|
o(input.attributes["checked"]).equals(undefined)
|
||||||
|
|
||||||
input.setAttribute("checked", "")
|
input.setAttribute("checked", "")
|
||||||
|
|
||||||
o(input.checked).equals(true)
|
o(input.checked).equals(true)
|
||||||
o(input.attributes["checked"].nodeValue).equals("")
|
o(input.attributes["checked"].nodeValue).equals("")
|
||||||
|
|
||||||
input.removeAttribute("checked")
|
input.removeAttribute("checked")
|
||||||
|
|
||||||
o(input.checked).equals(false)
|
o(input.checked).equals(false)
|
||||||
o(input.attributes["checked"]).equals(undefined)
|
o(input.attributes["checked"]).equals(undefined)
|
||||||
})
|
})
|
||||||
|
|
@ -610,27 +610,27 @@ o.spec("domMock", function() {
|
||||||
var input = $document.createElement("input")
|
var input = $document.createElement("input")
|
||||||
input.setAttribute("type", "checkbox")
|
input.setAttribute("type", "checkbox")
|
||||||
input.checked = true
|
input.checked = true
|
||||||
|
|
||||||
o(input.checked).equals(true)
|
o(input.checked).equals(true)
|
||||||
o(input.attributes["checked"]).equals(undefined)
|
o(input.attributes["checked"]).equals(undefined)
|
||||||
|
|
||||||
input.checked = false
|
input.checked = false
|
||||||
input.setAttribute("checked", "")
|
input.setAttribute("checked", "")
|
||||||
|
|
||||||
input.checked = true
|
input.checked = true
|
||||||
input.removeAttribute("checked")
|
input.removeAttribute("checked")
|
||||||
|
|
||||||
o(input.checked).equals(true)
|
o(input.checked).equals(true)
|
||||||
})
|
})
|
||||||
o("toggles on click", function() {
|
o("toggles on click", function() {
|
||||||
var input = $document.createElement("input")
|
var input = $document.createElement("input")
|
||||||
input.setAttribute("type", "checkbox")
|
input.setAttribute("type", "checkbox")
|
||||||
input.checked = false
|
input.checked = false
|
||||||
|
|
||||||
var e = $document.createEvent("MouseEvents")
|
var e = $document.createEvent("MouseEvents")
|
||||||
e.initEvent("click", true, true)
|
e.initEvent("click", true, true)
|
||||||
input.dispatchEvent(e)
|
input.dispatchEvent(e)
|
||||||
|
|
||||||
o(input.checked).equals(true)
|
o(input.checked).equals(true)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
@ -638,7 +638,7 @@ o.spec("domMock", function() {
|
||||||
o("only exists in input elements", function() {
|
o("only exists in input elements", function() {
|
||||||
var input = $document.createElement("input")
|
var input = $document.createElement("input")
|
||||||
var a = $document.createElement("a")
|
var a = $document.createElement("a")
|
||||||
|
|
||||||
o("value" in input).equals(true)
|
o("value" in input).equals(true)
|
||||||
o("value" in a).equals(false)
|
o("value" in a).equals(false)
|
||||||
})
|
})
|
||||||
|
|
@ -647,14 +647,14 @@ o.spec("domMock", function() {
|
||||||
o("reads from child if no value", function() {
|
o("reads from child if no value", function() {
|
||||||
var input = $document.createElement("textarea")
|
var input = $document.createElement("textarea")
|
||||||
input.appendChild($document.createTextNode("aaa"))
|
input.appendChild($document.createTextNode("aaa"))
|
||||||
|
|
||||||
o(input.value).equals("aaa")
|
o(input.value).equals("aaa")
|
||||||
})
|
})
|
||||||
o("ignores child if value set", function() {
|
o("ignores child if value set", function() {
|
||||||
var input = $document.createElement("textarea")
|
var input = $document.createElement("textarea")
|
||||||
input.value = "aaa"
|
input.value = "aaa"
|
||||||
input.setAttribute("value", "bbb")
|
input.setAttribute("value", "bbb")
|
||||||
|
|
||||||
o(input.value).equals("aaa")
|
o(input.value).equals("aaa")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
@ -662,37 +662,37 @@ o.spec("domMock", function() {
|
||||||
o("only exist in select elements", function() {
|
o("only exist in select elements", function() {
|
||||||
var select = $document.createElement("select")
|
var select = $document.createElement("select")
|
||||||
var a = $document.createElement("a")
|
var a = $document.createElement("a")
|
||||||
|
|
||||||
o("value" in select).equals(true)
|
o("value" in select).equals(true)
|
||||||
o("value" in a).equals(false)
|
o("value" in a).equals(false)
|
||||||
|
|
||||||
o("selectedIndex" in select).equals(true)
|
o("selectedIndex" in select).equals(true)
|
||||||
o("selectedIndex" in a).equals(false)
|
o("selectedIndex" in a).equals(false)
|
||||||
})
|
})
|
||||||
o("value defaults to value at first index", function() {
|
o("value defaults to value at first index", function() {
|
||||||
var select = $document.createElement("select")
|
var select = $document.createElement("select")
|
||||||
|
|
||||||
var option1 = $document.createElement("option")
|
var option1 = $document.createElement("option")
|
||||||
option1.setAttribute("value", "a")
|
option1.setAttribute("value", "a")
|
||||||
select.appendChild(option1)
|
select.appendChild(option1)
|
||||||
|
|
||||||
var option2 = $document.createElement("option")
|
var option2 = $document.createElement("option")
|
||||||
option2.setAttribute("value", "b")
|
option2.setAttribute("value", "b")
|
||||||
select.appendChild(option2)
|
select.appendChild(option2)
|
||||||
|
|
||||||
o(select.value).equals("a")
|
o(select.value).equals("a")
|
||||||
o(select.selectedIndex).equals(0)
|
o(select.selectedIndex).equals(0)
|
||||||
})
|
})
|
||||||
o("value falls back to child nodeValue if no attribute", function() {
|
o("value falls back to child nodeValue if no attribute", function() {
|
||||||
var select = $document.createElement("select")
|
var select = $document.createElement("select")
|
||||||
|
|
||||||
var option1 = $document.createElement("option")
|
var option1 = $document.createElement("option")
|
||||||
option1.appendChild($document.createTextNode("a"))
|
option1.appendChild($document.createTextNode("a"))
|
||||||
var option2 = $document.createElement("option")
|
var option2 = $document.createElement("option")
|
||||||
option2.appendChild($document.createTextNode("b"))
|
option2.appendChild($document.createTextNode("b"))
|
||||||
select.appendChild(option1)
|
select.appendChild(option1)
|
||||||
select.appendChild(option2)
|
select.appendChild(option2)
|
||||||
|
|
||||||
o(select.value).equals("a")
|
o(select.value).equals("a")
|
||||||
o(select.selectedIndex).equals(0)
|
o(select.selectedIndex).equals(0)
|
||||||
o(select.childNodes[0].selected).equals(true)
|
o(select.childNodes[0].selected).equals(true)
|
||||||
|
|
@ -701,159 +701,159 @@ o.spec("domMock", function() {
|
||||||
})
|
})
|
||||||
o("value defaults to invalid if no options", function() {
|
o("value defaults to invalid if no options", function() {
|
||||||
var select = $document.createElement("select")
|
var select = $document.createElement("select")
|
||||||
|
|
||||||
o(select.value).equals("")
|
o(select.value).equals("")
|
||||||
o(select.selectedIndex).equals(-1)
|
o(select.selectedIndex).equals(-1)
|
||||||
})
|
})
|
||||||
o("setting valid value works", function() {
|
o("setting valid value works", function() {
|
||||||
var select = $document.createElement("select")
|
var select = $document.createElement("select")
|
||||||
|
|
||||||
var option1 = $document.createElement("option")
|
var option1 = $document.createElement("option")
|
||||||
option1.setAttribute("value", "a")
|
option1.setAttribute("value", "a")
|
||||||
select.appendChild(option1)
|
select.appendChild(option1)
|
||||||
|
|
||||||
var option2 = $document.createElement("option")
|
var option2 = $document.createElement("option")
|
||||||
option2.setAttribute("value", "b")
|
option2.setAttribute("value", "b")
|
||||||
select.appendChild(option2)
|
select.appendChild(option2)
|
||||||
|
|
||||||
select.value = "b"
|
select.value = "b"
|
||||||
|
|
||||||
o(select.value).equals("b")
|
o(select.value).equals("b")
|
||||||
o(select.selectedIndex).equals(1)
|
o(select.selectedIndex).equals(1)
|
||||||
})
|
})
|
||||||
o("setting valid value works with optgroup", function() {
|
o("setting valid value works with optgroup", function() {
|
||||||
var select = $document.createElement("select")
|
var select = $document.createElement("select")
|
||||||
|
|
||||||
var option1 = $document.createElement("option")
|
var option1 = $document.createElement("option")
|
||||||
option1.setAttribute("value", "a")
|
option1.setAttribute("value", "a")
|
||||||
|
|
||||||
var option2 = $document.createElement("option")
|
var option2 = $document.createElement("option")
|
||||||
option2.setAttribute("value", "b")
|
option2.setAttribute("value", "b")
|
||||||
|
|
||||||
var option3 = $document.createElement("option")
|
var option3 = $document.createElement("option")
|
||||||
option3.setAttribute("value", "c")
|
option3.setAttribute("value", "c")
|
||||||
|
|
||||||
var optgroup = $document.createElement("optgroup")
|
var optgroup = $document.createElement("optgroup")
|
||||||
optgroup.appendChild(option1)
|
optgroup.appendChild(option1)
|
||||||
optgroup.appendChild(option2)
|
optgroup.appendChild(option2)
|
||||||
select.appendChild(optgroup)
|
select.appendChild(optgroup)
|
||||||
select.appendChild(option3)
|
select.appendChild(option3)
|
||||||
|
|
||||||
select.value = "b"
|
select.value = "b"
|
||||||
|
|
||||||
o(select.value).equals("b")
|
o(select.value).equals("b")
|
||||||
o(select.selectedIndex).equals(1)
|
o(select.selectedIndex).equals(1)
|
||||||
})
|
})
|
||||||
o("setting valid selectedIndex works", function() {
|
o("setting valid selectedIndex works", function() {
|
||||||
var select = $document.createElement("select")
|
var select = $document.createElement("select")
|
||||||
|
|
||||||
var option1 = $document.createElement("option")
|
var option1 = $document.createElement("option")
|
||||||
option1.setAttribute("value", "a")
|
option1.setAttribute("value", "a")
|
||||||
select.appendChild(option1)
|
select.appendChild(option1)
|
||||||
|
|
||||||
var option2 = $document.createElement("option")
|
var option2 = $document.createElement("option")
|
||||||
option2.setAttribute("value", "b")
|
option2.setAttribute("value", "b")
|
||||||
select.appendChild(option2)
|
select.appendChild(option2)
|
||||||
|
|
||||||
select.selectedIndex = 1
|
select.selectedIndex = 1
|
||||||
|
|
||||||
o(select.value).equals("b")
|
o(select.value).equals("b")
|
||||||
o(select.selectedIndex).equals(1)
|
o(select.selectedIndex).equals(1)
|
||||||
})
|
})
|
||||||
o("setting option[selected] works", function() {
|
o("setting option[selected] works", function() {
|
||||||
var select = $document.createElement("select")
|
var select = $document.createElement("select")
|
||||||
|
|
||||||
var option1 = $document.createElement("option")
|
var option1 = $document.createElement("option")
|
||||||
option1.setAttribute("value", "a")
|
option1.setAttribute("value", "a")
|
||||||
select.appendChild(option1)
|
select.appendChild(option1)
|
||||||
|
|
||||||
var option2 = $document.createElement("option")
|
var option2 = $document.createElement("option")
|
||||||
option2.setAttribute("value", "b")
|
option2.setAttribute("value", "b")
|
||||||
select.appendChild(option2)
|
select.appendChild(option2)
|
||||||
|
|
||||||
select.childNodes[1].selected = true
|
select.childNodes[1].selected = true
|
||||||
|
|
||||||
o(select.value).equals("b")
|
o(select.value).equals("b")
|
||||||
o(select.selectedIndex).equals(1)
|
o(select.selectedIndex).equals(1)
|
||||||
})
|
})
|
||||||
o("unsetting option[selected] works", function() {
|
o("unsetting option[selected] works", function() {
|
||||||
var select = $document.createElement("select")
|
var select = $document.createElement("select")
|
||||||
|
|
||||||
var option1 = $document.createElement("option")
|
var option1 = $document.createElement("option")
|
||||||
option1.setAttribute("value", "a")
|
option1.setAttribute("value", "a")
|
||||||
select.appendChild(option1)
|
select.appendChild(option1)
|
||||||
|
|
||||||
var option2 = $document.createElement("option")
|
var option2 = $document.createElement("option")
|
||||||
option2.setAttribute("value", "b")
|
option2.setAttribute("value", "b")
|
||||||
select.appendChild(option2)
|
select.appendChild(option2)
|
||||||
|
|
||||||
select.childNodes[1].selected = true
|
select.childNodes[1].selected = true
|
||||||
select.childNodes[1].selected = false
|
select.childNodes[1].selected = false
|
||||||
|
|
||||||
o(select.value).equals("a")
|
o(select.value).equals("a")
|
||||||
o(select.selectedIndex).equals(0)
|
o(select.selectedIndex).equals(0)
|
||||||
})
|
})
|
||||||
o("setting invalid value yields a selectedIndex of -1 and value of empty string", function() {
|
o("setting invalid value yields a selectedIndex of -1 and value of empty string", function() {
|
||||||
var select = $document.createElement("select")
|
var select = $document.createElement("select")
|
||||||
|
|
||||||
var option1 = $document.createElement("option")
|
var option1 = $document.createElement("option")
|
||||||
option1.setAttribute("value", "a")
|
option1.setAttribute("value", "a")
|
||||||
select.appendChild(option1)
|
select.appendChild(option1)
|
||||||
|
|
||||||
var option2 = $document.createElement("option")
|
var option2 = $document.createElement("option")
|
||||||
option2.setAttribute("value", "b")
|
option2.setAttribute("value", "b")
|
||||||
select.appendChild(option2)
|
select.appendChild(option2)
|
||||||
|
|
||||||
select.value = "c"
|
select.value = "c"
|
||||||
|
|
||||||
o(select.value).equals("")
|
o(select.value).equals("")
|
||||||
o(select.selectedIndex).equals(-1)
|
o(select.selectedIndex).equals(-1)
|
||||||
})
|
})
|
||||||
o("setting invalid selectedIndex yields a selectedIndex of -1 and value of empty string", function() {
|
o("setting invalid selectedIndex yields a selectedIndex of -1 and value of empty string", function() {
|
||||||
var select = $document.createElement("select")
|
var select = $document.createElement("select")
|
||||||
|
|
||||||
var option1 = $document.createElement("option")
|
var option1 = $document.createElement("option")
|
||||||
option1.setAttribute("value", "a")
|
option1.setAttribute("value", "a")
|
||||||
select.appendChild(option1)
|
select.appendChild(option1)
|
||||||
|
|
||||||
var option2 = $document.createElement("option")
|
var option2 = $document.createElement("option")
|
||||||
option2.setAttribute("value", "b")
|
option2.setAttribute("value", "b")
|
||||||
select.appendChild(option2)
|
select.appendChild(option2)
|
||||||
|
|
||||||
select.selectedIndex = -2
|
select.selectedIndex = -2
|
||||||
|
|
||||||
o(select.value).equals("")
|
o(select.value).equals("")
|
||||||
o(select.selectedIndex).equals(-1)
|
o(select.selectedIndex).equals(-1)
|
||||||
})
|
})
|
||||||
o("setting invalid value yields a selectedIndex of -1 and value of empty string even when there's an option whose value is empty string", function() {
|
o("setting invalid value yields a selectedIndex of -1 and value of empty string even when there's an option whose value is empty string", function() {
|
||||||
var select = $document.createElement("select")
|
var select = $document.createElement("select")
|
||||||
|
|
||||||
var option1 = $document.createElement("option")
|
var option1 = $document.createElement("option")
|
||||||
option1.setAttribute("value", "a")
|
option1.setAttribute("value", "a")
|
||||||
select.appendChild(option1)
|
select.appendChild(option1)
|
||||||
|
|
||||||
var option2 = $document.createElement("option")
|
var option2 = $document.createElement("option")
|
||||||
option2.setAttribute("value", "")
|
option2.setAttribute("value", "")
|
||||||
select.appendChild(option2)
|
select.appendChild(option2)
|
||||||
|
|
||||||
select.value = "c"
|
select.value = "c"
|
||||||
|
|
||||||
o(select.value).equals("")
|
o(select.value).equals("")
|
||||||
o(select.selectedIndex).equals(-1)
|
o(select.selectedIndex).equals(-1)
|
||||||
})
|
})
|
||||||
o("setting invalid selectedIndex yields a selectedIndex of -1 and value of empty string even when there's an option whose value is empty string", function() {
|
o("setting invalid selectedIndex yields a selectedIndex of -1 and value of empty string even when there's an option whose value is empty string", function() {
|
||||||
var select = $document.createElement("select")
|
var select = $document.createElement("select")
|
||||||
|
|
||||||
var option1 = $document.createElement("option")
|
var option1 = $document.createElement("option")
|
||||||
option1.setAttribute("value", "a")
|
option1.setAttribute("value", "a")
|
||||||
select.appendChild(option1)
|
select.appendChild(option1)
|
||||||
|
|
||||||
var option2 = $document.createElement("option")
|
var option2 = $document.createElement("option")
|
||||||
option2.setAttribute("value", "")
|
option2.setAttribute("value", "")
|
||||||
select.appendChild(option2)
|
select.appendChild(option2)
|
||||||
|
|
||||||
select.selectedIndex = -2
|
select.selectedIndex = -2
|
||||||
|
|
||||||
o(select.value).equals("")
|
o(select.value).equals("")
|
||||||
o(select.selectedIndex).equals(-1)
|
o(select.selectedIndex).equals(-1)
|
||||||
})
|
})
|
||||||
|
|
@ -863,7 +863,7 @@ o.spec("domMock", function() {
|
||||||
o("works", function() {
|
o("works", function() {
|
||||||
var el = $document.createElement("div")
|
var el = $document.createElement("div")
|
||||||
el.className = "a"
|
el.className = "a"
|
||||||
|
|
||||||
o(el.className).equals("a")
|
o(el.className).equals("a")
|
||||||
o(el.attributes["class"].nodeValue).equals("a")
|
o(el.attributes["class"].nodeValue).equals("a")
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ var parseURL = require("../../test-utils/parseURL")
|
||||||
|
|
||||||
o.spec("parseURL", function() {
|
o.spec("parseURL", function() {
|
||||||
var root = {protocol: "http:", hostname: "localhost", port: "", pathname: "/"}
|
var root = {protocol: "http:", hostname: "localhost", port: "", pathname: "/"}
|
||||||
|
|
||||||
o.spec("full URL", function() {
|
o.spec("full URL", function() {
|
||||||
o("parses full URL", function() {
|
o("parses full URL", function() {
|
||||||
var data = parseURL("http://www.google.com:80/test?a=b#c")
|
var data = parseURL("http://www.google.com:80/test?a=b#c")
|
||||||
|
|
@ -147,4 +147,4 @@ o.spec("parseURL", function() {
|
||||||
o(data.pathname).equals("/a:b")
|
o(data.pathname).equals("/a:b")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -4,30 +4,30 @@ var o = require("../../ospec/ospec")
|
||||||
var pushStateMock = require("../../test-utils/pushStateMock")
|
var pushStateMock = require("../../test-utils/pushStateMock")
|
||||||
|
|
||||||
o.spec("pushStateMock", function() {
|
o.spec("pushStateMock", function() {
|
||||||
|
|
||||||
var $window
|
var $window
|
||||||
o.beforeEach(function() {
|
o.beforeEach(function() {
|
||||||
$window = pushStateMock()
|
$window = pushStateMock()
|
||||||
})
|
})
|
||||||
|
|
||||||
o.spec("initial state", function() {
|
o.spec("initial state", function() {
|
||||||
o("has url on page load", function() {
|
o("has url on page load", function() {
|
||||||
o($window.location.href).equals("http://localhost/")
|
o($window.location.href).equals("http://localhost/")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
o.spec("set href", function() {
|
o.spec("set href", function() {
|
||||||
o("changes url on location.href change", function() {
|
o("changes url on location.href change", function() {
|
||||||
var old = $window.location.href
|
var old = $window.location.href
|
||||||
$window.location.href = "http://localhost/a"
|
$window.location.href = "http://localhost/a"
|
||||||
|
|
||||||
o(old).equals("http://localhost/")
|
o(old).equals("http://localhost/")
|
||||||
o($window.location.href).equals("http://localhost/a")
|
o($window.location.href).equals("http://localhost/a")
|
||||||
})
|
})
|
||||||
o("changes url on relative location.href change", function() {
|
o("changes url on relative location.href change", function() {
|
||||||
var old = $window.location.href
|
var old = $window.location.href
|
||||||
$window.location.href = "a"
|
$window.location.href = "a"
|
||||||
|
|
||||||
o(old).equals("http://localhost/")
|
o(old).equals("http://localhost/")
|
||||||
o($window.location.href).equals("http://localhost/a")
|
o($window.location.href).equals("http://localhost/a")
|
||||||
o($window.location.pathname).equals("/a")
|
o($window.location.pathname).equals("/a")
|
||||||
|
|
@ -36,7 +36,7 @@ o.spec("pushStateMock", function() {
|
||||||
$window.location.href = "a"
|
$window.location.href = "a"
|
||||||
var old = $window.location.href
|
var old = $window.location.href
|
||||||
$window.location.href = ".."
|
$window.location.href = ".."
|
||||||
|
|
||||||
o(old).equals("http://localhost/a")
|
o(old).equals("http://localhost/a")
|
||||||
o($window.location.href).equals("http://localhost/")
|
o($window.location.href).equals("http://localhost/")
|
||||||
o($window.location.pathname).equals("/")
|
o($window.location.pathname).equals("/")
|
||||||
|
|
@ -45,7 +45,7 @@ o.spec("pushStateMock", function() {
|
||||||
$window.location.href = "a/b/c"
|
$window.location.href = "a/b/c"
|
||||||
var old = $window.location.href
|
var old = $window.location.href
|
||||||
$window.location.href = ".."
|
$window.location.href = ".."
|
||||||
|
|
||||||
o(old).equals("http://localhost/a/b/c")
|
o(old).equals("http://localhost/a/b/c")
|
||||||
o($window.location.href).equals("http://localhost/a")
|
o($window.location.href).equals("http://localhost/a")
|
||||||
o($window.location.pathname).equals("/a")
|
o($window.location.pathname).equals("/a")
|
||||||
|
|
@ -53,7 +53,7 @@ o.spec("pushStateMock", function() {
|
||||||
o("does not change url on dotdot location.href change from root", function() {
|
o("does not change url on dotdot location.href change from root", function() {
|
||||||
var old = $window.location.href
|
var old = $window.location.href
|
||||||
$window.location.href = ".."
|
$window.location.href = ".."
|
||||||
|
|
||||||
o(old).equals("http://localhost/")
|
o(old).equals("http://localhost/")
|
||||||
o($window.location.href).equals("http://localhost/")
|
o($window.location.href).equals("http://localhost/")
|
||||||
o($window.location.pathname).equals("/")
|
o($window.location.pathname).equals("/")
|
||||||
|
|
@ -62,7 +62,7 @@ o.spec("pushStateMock", function() {
|
||||||
var old = $window.location.href
|
var old = $window.location.href
|
||||||
$window.location.href = "a"
|
$window.location.href = "a"
|
||||||
$window.location.href = "./b"
|
$window.location.href = "./b"
|
||||||
|
|
||||||
o(old).equals("http://localhost/")
|
o(old).equals("http://localhost/")
|
||||||
o($window.location.href).equals("http://localhost/b")
|
o($window.location.href).equals("http://localhost/b")
|
||||||
o($window.location.pathname).equals("/b")
|
o($window.location.pathname).equals("/b")
|
||||||
|
|
@ -71,7 +71,7 @@ o.spec("pushStateMock", function() {
|
||||||
var old = $window.location.href
|
var old = $window.location.href
|
||||||
$window.location.href = "a"
|
$window.location.href = "a"
|
||||||
$window.location.href = "."
|
$window.location.href = "."
|
||||||
|
|
||||||
o(old).equals("http://localhost/")
|
o(old).equals("http://localhost/")
|
||||||
o($window.location.href).equals("http://localhost/a")
|
o($window.location.href).equals("http://localhost/a")
|
||||||
o($window.location.pathname).equals("/a")
|
o($window.location.pathname).equals("/a")
|
||||||
|
|
@ -79,7 +79,7 @@ o.spec("pushStateMock", function() {
|
||||||
o("changes url on hash-only location.href change", function() {
|
o("changes url on hash-only location.href change", function() {
|
||||||
var old = $window.location.href
|
var old = $window.location.href
|
||||||
$window.location.href = "#a"
|
$window.location.href = "#a"
|
||||||
|
|
||||||
o(old).equals("http://localhost/")
|
o(old).equals("http://localhost/")
|
||||||
o($window.location.href).equals("http://localhost/#a")
|
o($window.location.href).equals("http://localhost/#a")
|
||||||
o($window.location.hash).equals("#a")
|
o($window.location.hash).equals("#a")
|
||||||
|
|
@ -87,7 +87,7 @@ o.spec("pushStateMock", function() {
|
||||||
o("changes url on search-only location.href change", function() {
|
o("changes url on search-only location.href change", function() {
|
||||||
var old = $window.location.href
|
var old = $window.location.href
|
||||||
$window.location.href = "?a"
|
$window.location.href = "?a"
|
||||||
|
|
||||||
o(old).equals("http://localhost/")
|
o(old).equals("http://localhost/")
|
||||||
o($window.location.href).equals("http://localhost/?a")
|
o($window.location.href).equals("http://localhost/?a")
|
||||||
o($window.location.search).equals("?a")
|
o($window.location.search).equals("?a")
|
||||||
|
|
@ -95,7 +95,7 @@ o.spec("pushStateMock", function() {
|
||||||
o("changes hash on location.href change", function() {
|
o("changes hash on location.href change", function() {
|
||||||
var old = $window.location.href
|
var old = $window.location.href
|
||||||
$window.location.href = "http://localhost/a#b"
|
$window.location.href = "http://localhost/a#b"
|
||||||
|
|
||||||
o(old).equals("http://localhost/")
|
o(old).equals("http://localhost/")
|
||||||
o($window.location.href).equals("http://localhost/a#b")
|
o($window.location.href).equals("http://localhost/a#b")
|
||||||
o($window.location.hash).equals("#b")
|
o($window.location.hash).equals("#b")
|
||||||
|
|
@ -103,7 +103,7 @@ o.spec("pushStateMock", function() {
|
||||||
o("changes search on location.href change", function() {
|
o("changes search on location.href change", function() {
|
||||||
var old = $window.location.href
|
var old = $window.location.href
|
||||||
$window.location.href = "http://localhost/a?b"
|
$window.location.href = "http://localhost/a?b"
|
||||||
|
|
||||||
o(old).equals("http://localhost/")
|
o(old).equals("http://localhost/")
|
||||||
o($window.location.href).equals("http://localhost/a?b")
|
o($window.location.href).equals("http://localhost/a?b")
|
||||||
o($window.location.search).equals("?b")
|
o($window.location.search).equals("?b")
|
||||||
|
|
@ -111,7 +111,7 @@ o.spec("pushStateMock", function() {
|
||||||
o("changes search and hash on location.href change", function() {
|
o("changes search and hash on location.href change", function() {
|
||||||
var old = $window.location.href
|
var old = $window.location.href
|
||||||
$window.location.href = "http://localhost/a?b#c"
|
$window.location.href = "http://localhost/a?b#c"
|
||||||
|
|
||||||
o(old).equals("http://localhost/")
|
o(old).equals("http://localhost/")
|
||||||
o($window.location.href).equals("http://localhost/a?b#c")
|
o($window.location.href).equals("http://localhost/a?b#c")
|
||||||
o($window.location.search).equals("?b")
|
o($window.location.search).equals("?b")
|
||||||
|
|
@ -120,7 +120,7 @@ o.spec("pushStateMock", function() {
|
||||||
o("handles search with search and hash", function() {
|
o("handles search with search and hash", function() {
|
||||||
var old = $window.location.href
|
var old = $window.location.href
|
||||||
$window.location.href = "http://localhost/a?b?c#d"
|
$window.location.href = "http://localhost/a?b?c#d"
|
||||||
|
|
||||||
o(old).equals("http://localhost/")
|
o(old).equals("http://localhost/")
|
||||||
o($window.location.href).equals("http://localhost/a?b?c#d")
|
o($window.location.href).equals("http://localhost/a?b?c#d")
|
||||||
o($window.location.search).equals("?b?c")
|
o($window.location.search).equals("?b?c")
|
||||||
|
|
@ -129,7 +129,7 @@ o.spec("pushStateMock", function() {
|
||||||
o("handles hash with search and hash", function() {
|
o("handles hash with search and hash", function() {
|
||||||
var old = $window.location.href
|
var old = $window.location.href
|
||||||
$window.location.href = "http://localhost/a#b?c#d"
|
$window.location.href = "http://localhost/a#b?c#d"
|
||||||
|
|
||||||
o(old).equals("http://localhost/")
|
o(old).equals("http://localhost/")
|
||||||
o($window.location.href).equals("http://localhost/a#b?c#d")
|
o($window.location.href).equals("http://localhost/a#b?c#d")
|
||||||
o($window.location.search).equals("")
|
o($window.location.search).equals("")
|
||||||
|
|
@ -140,7 +140,7 @@ o.spec("pushStateMock", function() {
|
||||||
o("changes url on location.search change", function() {
|
o("changes url on location.search change", function() {
|
||||||
var old = $window.location.href
|
var old = $window.location.href
|
||||||
$window.location.search = "?b"
|
$window.location.search = "?b"
|
||||||
|
|
||||||
o(old).equals("http://localhost/")
|
o(old).equals("http://localhost/")
|
||||||
o($window.location.href).equals("http://localhost/?b")
|
o($window.location.href).equals("http://localhost/?b")
|
||||||
o($window.location.search).equals("?b")
|
o($window.location.search).equals("?b")
|
||||||
|
|
@ -150,7 +150,7 @@ o.spec("pushStateMock", function() {
|
||||||
o("changes url on location.hash change", function() {
|
o("changes url on location.hash change", function() {
|
||||||
var old = $window.location.href
|
var old = $window.location.href
|
||||||
$window.location.hash = "#b"
|
$window.location.hash = "#b"
|
||||||
|
|
||||||
o(old).equals("http://localhost/")
|
o(old).equals("http://localhost/")
|
||||||
o($window.location.href).equals("http://localhost/#b")
|
o($window.location.href).equals("http://localhost/#b")
|
||||||
o($window.location.hash).equals("#b")
|
o($window.location.hash).equals("#b")
|
||||||
|
|
@ -160,7 +160,7 @@ o.spec("pushStateMock", function() {
|
||||||
o("changes url on location.pathname change", function() {
|
o("changes url on location.pathname change", function() {
|
||||||
var old = $window.location.href
|
var old = $window.location.href
|
||||||
$window.location.pathname = "/a"
|
$window.location.pathname = "/a"
|
||||||
|
|
||||||
o(old).equals("http://localhost/")
|
o(old).equals("http://localhost/")
|
||||||
o($window.location.href).equals("http://localhost/a")
|
o($window.location.href).equals("http://localhost/a")
|
||||||
o($window.location.pathname).equals("/a")
|
o($window.location.pathname).equals("/a")
|
||||||
|
|
@ -181,7 +181,7 @@ o.spec("pushStateMock", function() {
|
||||||
o("setting origin changes href", function() {
|
o("setting origin changes href", function() {
|
||||||
var old = $window.location.href
|
var old = $window.location.href
|
||||||
$window.location.port = "81"
|
$window.location.port = "81"
|
||||||
|
|
||||||
o(old).equals("http://localhost/")
|
o(old).equals("http://localhost/")
|
||||||
o($window.location.port).equals("81")
|
o($window.location.port).equals("81")
|
||||||
o($window.location.href).equals("http://localhost:81/")
|
o($window.location.href).equals("http://localhost:81/")
|
||||||
|
|
@ -191,7 +191,7 @@ o.spec("pushStateMock", function() {
|
||||||
o("setting hostname changes href", function() {
|
o("setting hostname changes href", function() {
|
||||||
var old = $window.location.href
|
var old = $window.location.href
|
||||||
$window.location.hostname = "127.0.0.1"
|
$window.location.hostname = "127.0.0.1"
|
||||||
|
|
||||||
o(old).equals("http://localhost/")
|
o(old).equals("http://localhost/")
|
||||||
o($window.location.hostname).equals("127.0.0.1")
|
o($window.location.hostname).equals("127.0.0.1")
|
||||||
o($window.location.href).equals("http://127.0.0.1/")
|
o($window.location.href).equals("http://127.0.0.1/")
|
||||||
|
|
@ -201,7 +201,7 @@ o.spec("pushStateMock", function() {
|
||||||
o("setting origin is ignored", function() {
|
o("setting origin is ignored", function() {
|
||||||
var old = $window.location.href
|
var old = $window.location.href
|
||||||
$window.location.origin = "http://127.0.0.1"
|
$window.location.origin = "http://127.0.0.1"
|
||||||
|
|
||||||
o(old).equals("http://localhost/")
|
o(old).equals("http://localhost/")
|
||||||
o($window.location.origin).equals("http://localhost")
|
o($window.location.origin).equals("http://localhost")
|
||||||
})
|
})
|
||||||
|
|
@ -210,7 +210,7 @@ o.spec("pushStateMock", function() {
|
||||||
o("setting host is ignored", function() {
|
o("setting host is ignored", function() {
|
||||||
var old = $window.location.href
|
var old = $window.location.href
|
||||||
$window.location.host = "http://127.0.0.1"
|
$window.location.host = "http://127.0.0.1"
|
||||||
|
|
||||||
o(old).equals("http://localhost/")
|
o(old).equals("http://localhost/")
|
||||||
o($window.location.host).equals("localhost")
|
o($window.location.host).equals("localhost")
|
||||||
})
|
})
|
||||||
|
|
@ -219,14 +219,14 @@ o.spec("pushStateMock", function() {
|
||||||
o("changes url on pushstate", function() {
|
o("changes url on pushstate", function() {
|
||||||
var old = $window.location.href
|
var old = $window.location.href
|
||||||
$window.history.pushState(null, null, "http://localhost/a")
|
$window.history.pushState(null, null, "http://localhost/a")
|
||||||
|
|
||||||
o(old).equals("http://localhost/")
|
o(old).equals("http://localhost/")
|
||||||
o($window.location.href).equals("http://localhost/a")
|
o($window.location.href).equals("http://localhost/a")
|
||||||
})
|
})
|
||||||
o("changes search on pushstate", function() {
|
o("changes search on pushstate", function() {
|
||||||
var old = $window.location.href
|
var old = $window.location.href
|
||||||
$window.history.pushState(null, null, "http://localhost/?a")
|
$window.history.pushState(null, null, "http://localhost/?a")
|
||||||
|
|
||||||
o(old).equals("http://localhost/")
|
o(old).equals("http://localhost/")
|
||||||
o($window.location.href).equals("http://localhost/?a")
|
o($window.location.href).equals("http://localhost/?a")
|
||||||
o($window.location.search).equals("?a")
|
o($window.location.search).equals("?a")
|
||||||
|
|
@ -234,7 +234,7 @@ o.spec("pushStateMock", function() {
|
||||||
o("changes search on relative pushstate", function() {
|
o("changes search on relative pushstate", function() {
|
||||||
var old = $window.location.href
|
var old = $window.location.href
|
||||||
$window.history.pushState(null, null, "?a")
|
$window.history.pushState(null, null, "?a")
|
||||||
|
|
||||||
o(old).equals("http://localhost/")
|
o(old).equals("http://localhost/")
|
||||||
o($window.location.href).equals("http://localhost/?a")
|
o($window.location.href).equals("http://localhost/?a")
|
||||||
o($window.location.search).equals("?a")
|
o($window.location.search).equals("?a")
|
||||||
|
|
@ -242,7 +242,7 @@ o.spec("pushStateMock", function() {
|
||||||
o("changes hash on pushstate", function() {
|
o("changes hash on pushstate", function() {
|
||||||
var old = $window.location.href
|
var old = $window.location.href
|
||||||
$window.history.pushState(null, null, "http://localhost/#a")
|
$window.history.pushState(null, null, "http://localhost/#a")
|
||||||
|
|
||||||
o(old).equals("http://localhost/")
|
o(old).equals("http://localhost/")
|
||||||
o($window.location.href).equals("http://localhost/#a")
|
o($window.location.href).equals("http://localhost/#a")
|
||||||
o($window.location.hash).equals("#a")
|
o($window.location.hash).equals("#a")
|
||||||
|
|
@ -250,7 +250,7 @@ o.spec("pushStateMock", function() {
|
||||||
o("changes hash on relative pushstate", function() {
|
o("changes hash on relative pushstate", function() {
|
||||||
var old = $window.location.href
|
var old = $window.location.href
|
||||||
$window.history.pushState(null, null, "#a")
|
$window.history.pushState(null, null, "#a")
|
||||||
|
|
||||||
o(old).equals("http://localhost/")
|
o(old).equals("http://localhost/")
|
||||||
o($window.location.href).equals("http://localhost/#a")
|
o($window.location.href).equals("http://localhost/#a")
|
||||||
o($window.location.hash).equals("#a")
|
o($window.location.hash).equals("#a")
|
||||||
|
|
@ -260,14 +260,14 @@ o.spec("pushStateMock", function() {
|
||||||
o("history.back() without history does not trigger onpopstate", function() {
|
o("history.back() without history does not trigger onpopstate", function() {
|
||||||
$window.onpopstate = o.spy()
|
$window.onpopstate = o.spy()
|
||||||
$window.history.back()
|
$window.history.back()
|
||||||
|
|
||||||
o($window.onpopstate.callCount).equals(0)
|
o($window.onpopstate.callCount).equals(0)
|
||||||
})
|
})
|
||||||
o("history.back() after pushstate triggers onpopstate", function() {
|
o("history.back() after pushstate triggers onpopstate", function() {
|
||||||
$window.onpopstate = o.spy()
|
$window.onpopstate = o.spy()
|
||||||
$window.history.pushState(null, null, "http://localhost/a")
|
$window.history.pushState(null, null, "http://localhost/a")
|
||||||
$window.history.back()
|
$window.history.back()
|
||||||
|
|
||||||
o($window.onpopstate.callCount).equals(1)
|
o($window.onpopstate.callCount).equals(1)
|
||||||
o($window.onpopstate.args[0].type).equals("popstate")
|
o($window.onpopstate.args[0].type).equals("popstate")
|
||||||
})
|
})
|
||||||
|
|
@ -275,63 +275,63 @@ o.spec("pushStateMock", function() {
|
||||||
$window.onpopstate = o.spy()
|
$window.onpopstate = o.spy()
|
||||||
$window.history.pushState(null, null, "a")
|
$window.history.pushState(null, null, "a")
|
||||||
$window.history.back()
|
$window.history.back()
|
||||||
|
|
||||||
o($window.onpopstate.callCount).equals(1)
|
o($window.onpopstate.callCount).equals(1)
|
||||||
})
|
})
|
||||||
o("history.back() after search pushstate triggers onpopstate", function() {
|
o("history.back() after search pushstate triggers onpopstate", function() {
|
||||||
$window.onpopstate = o.spy()
|
$window.onpopstate = o.spy()
|
||||||
$window.history.pushState(null, null, "http://localhost/?a")
|
$window.history.pushState(null, null, "http://localhost/?a")
|
||||||
$window.history.back()
|
$window.history.back()
|
||||||
|
|
||||||
o($window.onpopstate.callCount).equals(1)
|
o($window.onpopstate.callCount).equals(1)
|
||||||
})
|
})
|
||||||
o("history.back() after relative search pushstate triggers onpopstate", function() {
|
o("history.back() after relative search pushstate triggers onpopstate", function() {
|
||||||
$window.onpopstate = o.spy()
|
$window.onpopstate = o.spy()
|
||||||
$window.history.pushState(null, null, "?a")
|
$window.history.pushState(null, null, "?a")
|
||||||
$window.history.back()
|
$window.history.back()
|
||||||
|
|
||||||
o($window.onpopstate.callCount).equals(1)
|
o($window.onpopstate.callCount).equals(1)
|
||||||
})
|
})
|
||||||
o("history.back() after hash pushstate triggers onpopstate", function() {
|
o("history.back() after hash pushstate triggers onpopstate", function() {
|
||||||
$window.onpopstate = o.spy()
|
$window.onpopstate = o.spy()
|
||||||
$window.history.pushState(null, null, "http://localhost/#a")
|
$window.history.pushState(null, null, "http://localhost/#a")
|
||||||
$window.history.back()
|
$window.history.back()
|
||||||
|
|
||||||
o($window.onpopstate.callCount).equals(1)
|
o($window.onpopstate.callCount).equals(1)
|
||||||
})
|
})
|
||||||
o("history.back() after relative hash pushstate triggers onpopstate", function() {
|
o("history.back() after relative hash pushstate triggers onpopstate", function() {
|
||||||
$window.onpopstate = o.spy()
|
$window.onpopstate = o.spy()
|
||||||
$window.history.pushState(null, null, "#a")
|
$window.history.pushState(null, null, "#a")
|
||||||
$window.history.back()
|
$window.history.back()
|
||||||
|
|
||||||
o($window.onpopstate.callCount).equals(1)
|
o($window.onpopstate.callCount).equals(1)
|
||||||
})
|
})
|
||||||
o("history.back() after replacestate does not trigger onpopstate", function() {
|
o("history.back() after replacestate does not trigger onpopstate", function() {
|
||||||
$window.onpopstate = o.spy()
|
$window.onpopstate = o.spy()
|
||||||
$window.history.replaceState(null, null, "http://localhost/a")
|
$window.history.replaceState(null, null, "http://localhost/a")
|
||||||
$window.history.back()
|
$window.history.back()
|
||||||
|
|
||||||
o($window.onpopstate.callCount).equals(0)
|
o($window.onpopstate.callCount).equals(0)
|
||||||
})
|
})
|
||||||
o("history.back() after relative replacestate does not trigger onpopstate", function() {
|
o("history.back() after relative replacestate does not trigger onpopstate", function() {
|
||||||
$window.onpopstate = o.spy()
|
$window.onpopstate = o.spy()
|
||||||
$window.history.replaceState(null, null, "a")
|
$window.history.replaceState(null, null, "a")
|
||||||
$window.history.back()
|
$window.history.back()
|
||||||
|
|
||||||
o($window.onpopstate.callCount).equals(0)
|
o($window.onpopstate.callCount).equals(0)
|
||||||
})
|
})
|
||||||
o("history.back() after relative search replacestate does not trigger onpopstate", function() {
|
o("history.back() after relative search replacestate does not trigger onpopstate", function() {
|
||||||
$window.onpopstate = o.spy()
|
$window.onpopstate = o.spy()
|
||||||
$window.history.replaceState(null, null, "?a")
|
$window.history.replaceState(null, null, "?a")
|
||||||
$window.history.back()
|
$window.history.back()
|
||||||
|
|
||||||
o($window.onpopstate.callCount).equals(0)
|
o($window.onpopstate.callCount).equals(0)
|
||||||
})
|
})
|
||||||
o("history.back() after relative hash replacestate does not trigger onpopstate", function() {
|
o("history.back() after relative hash replacestate does not trigger onpopstate", function() {
|
||||||
$window.onpopstate = o.spy()
|
$window.onpopstate = o.spy()
|
||||||
$window.history.replaceState(null, null, "#a")
|
$window.history.replaceState(null, null, "#a")
|
||||||
$window.history.back()
|
$window.history.back()
|
||||||
|
|
||||||
o($window.onpopstate.callCount).equals(0)
|
o($window.onpopstate.callCount).equals(0)
|
||||||
})
|
})
|
||||||
o("history.forward() after pushstate triggers onpopstate", function() {
|
o("history.forward() after pushstate triggers onpopstate", function() {
|
||||||
|
|
@ -339,7 +339,7 @@ o.spec("pushStateMock", function() {
|
||||||
$window.history.pushState(null, null, "http://localhost/a")
|
$window.history.pushState(null, null, "http://localhost/a")
|
||||||
$window.history.back()
|
$window.history.back()
|
||||||
$window.history.forward()
|
$window.history.forward()
|
||||||
|
|
||||||
o($window.onpopstate.callCount).equals(2)
|
o($window.onpopstate.callCount).equals(2)
|
||||||
})
|
})
|
||||||
o("history.forward() after relative pushstate triggers onpopstate", function() {
|
o("history.forward() after relative pushstate triggers onpopstate", function() {
|
||||||
|
|
@ -347,7 +347,7 @@ o.spec("pushStateMock", function() {
|
||||||
$window.history.pushState(null, null, "a")
|
$window.history.pushState(null, null, "a")
|
||||||
$window.history.back()
|
$window.history.back()
|
||||||
$window.history.forward()
|
$window.history.forward()
|
||||||
|
|
||||||
o($window.onpopstate.callCount).equals(2)
|
o($window.onpopstate.callCount).equals(2)
|
||||||
})
|
})
|
||||||
o("history.forward() after search pushstate triggers onpopstate", function() {
|
o("history.forward() after search pushstate triggers onpopstate", function() {
|
||||||
|
|
@ -355,7 +355,7 @@ o.spec("pushStateMock", function() {
|
||||||
$window.history.pushState(null, null, "http://localhost/?a")
|
$window.history.pushState(null, null, "http://localhost/?a")
|
||||||
$window.history.back()
|
$window.history.back()
|
||||||
$window.history.forward()
|
$window.history.forward()
|
||||||
|
|
||||||
o($window.onpopstate.callCount).equals(2)
|
o($window.onpopstate.callCount).equals(2)
|
||||||
})
|
})
|
||||||
o("history.forward() after relative search pushstate triggers onpopstate", function() {
|
o("history.forward() after relative search pushstate triggers onpopstate", function() {
|
||||||
|
|
@ -363,7 +363,7 @@ o.spec("pushStateMock", function() {
|
||||||
$window.history.pushState(null, null, "?a")
|
$window.history.pushState(null, null, "?a")
|
||||||
$window.history.back()
|
$window.history.back()
|
||||||
$window.history.forward()
|
$window.history.forward()
|
||||||
|
|
||||||
o($window.onpopstate.callCount).equals(2)
|
o($window.onpopstate.callCount).equals(2)
|
||||||
})
|
})
|
||||||
o("history.forward() after hash pushstate triggers onpopstate", function() {
|
o("history.forward() after hash pushstate triggers onpopstate", function() {
|
||||||
|
|
@ -371,7 +371,7 @@ o.spec("pushStateMock", function() {
|
||||||
$window.history.pushState(null, null, "http://localhost/#a")
|
$window.history.pushState(null, null, "http://localhost/#a")
|
||||||
$window.history.back()
|
$window.history.back()
|
||||||
$window.history.forward()
|
$window.history.forward()
|
||||||
|
|
||||||
o($window.onpopstate.callCount).equals(2)
|
o($window.onpopstate.callCount).equals(2)
|
||||||
})
|
})
|
||||||
o("history.forward() after relative hash pushstate triggers onpopstate", function() {
|
o("history.forward() after relative hash pushstate triggers onpopstate", function() {
|
||||||
|
|
@ -379,33 +379,33 @@ o.spec("pushStateMock", function() {
|
||||||
$window.history.pushState(null, null, "#a")
|
$window.history.pushState(null, null, "#a")
|
||||||
$window.history.back()
|
$window.history.back()
|
||||||
$window.history.forward()
|
$window.history.forward()
|
||||||
|
|
||||||
o($window.onpopstate.callCount).equals(2)
|
o($window.onpopstate.callCount).equals(2)
|
||||||
})
|
})
|
||||||
o("history.back() without history does not trigger onpopstate", function() {
|
o("history.back() without history does not trigger onpopstate", function() {
|
||||||
$window.onpopstate = o.spy()
|
$window.onpopstate = o.spy()
|
||||||
$window.history.back()
|
$window.history.back()
|
||||||
|
|
||||||
o($window.onpopstate.callCount).equals(0)
|
o($window.onpopstate.callCount).equals(0)
|
||||||
})
|
})
|
||||||
o("history.forward() without history does not trigger onpopstate", function() {
|
o("history.forward() without history does not trigger onpopstate", function() {
|
||||||
$window.onpopstate = o.spy()
|
$window.onpopstate = o.spy()
|
||||||
$window.history.forward()
|
$window.history.forward()
|
||||||
|
|
||||||
o($window.onpopstate.callCount).equals(0)
|
o($window.onpopstate.callCount).equals(0)
|
||||||
})
|
})
|
||||||
o("history navigation without history does not trigger onpopstate", function() {
|
o("history navigation without history does not trigger onpopstate", function() {
|
||||||
$window.onpopstate = o.spy()
|
$window.onpopstate = o.spy()
|
||||||
$window.history.back()
|
$window.history.back()
|
||||||
$window.history.forward()
|
$window.history.forward()
|
||||||
|
|
||||||
o($window.onpopstate.callCount).equals(0)
|
o($window.onpopstate.callCount).equals(0)
|
||||||
})
|
})
|
||||||
o("reverse history navigation without history does not trigger onpopstate", function() {
|
o("reverse history navigation without history does not trigger onpopstate", function() {
|
||||||
$window.onpopstate = o.spy()
|
$window.onpopstate = o.spy()
|
||||||
$window.history.forward()
|
$window.history.forward()
|
||||||
$window.history.back()
|
$window.history.back()
|
||||||
|
|
||||||
o($window.onpopstate.callCount).equals(0)
|
o($window.onpopstate.callCount).equals(0)
|
||||||
})
|
})
|
||||||
o("onpopstate has correct url during call", function(done) {
|
o("onpopstate has correct url during call", function(done) {
|
||||||
|
|
@ -422,47 +422,47 @@ o.spec("pushStateMock", function() {
|
||||||
o("onhashchange triggers on location.href change", function() {
|
o("onhashchange triggers on location.href change", function() {
|
||||||
$window.onhashchange = o.spy()
|
$window.onhashchange = o.spy()
|
||||||
$window.location.href = "http://localhost/#a"
|
$window.location.href = "http://localhost/#a"
|
||||||
|
|
||||||
o($window.onhashchange.callCount).equals(1)
|
o($window.onhashchange.callCount).equals(1)
|
||||||
o($window.onhashchange.args[0].type).equals("hashchange")
|
o($window.onhashchange.args[0].type).equals("hashchange")
|
||||||
})
|
})
|
||||||
o("onhashchange triggers on relative location.href change", function() {
|
o("onhashchange triggers on relative location.href change", function() {
|
||||||
$window.onhashchange = o.spy()
|
$window.onhashchange = o.spy()
|
||||||
$window.location.href = "#a"
|
$window.location.href = "#a"
|
||||||
|
|
||||||
o($window.onhashchange.callCount).equals(1)
|
o($window.onhashchange.callCount).equals(1)
|
||||||
})
|
})
|
||||||
o("onhashchange triggers on location.hash change", function() {
|
o("onhashchange triggers on location.hash change", function() {
|
||||||
$window.onhashchange = o.spy()
|
$window.onhashchange = o.spy()
|
||||||
$window.location.hash = "#a"
|
$window.location.hash = "#a"
|
||||||
|
|
||||||
o($window.onhashchange.callCount).equals(1)
|
o($window.onhashchange.callCount).equals(1)
|
||||||
})
|
})
|
||||||
o("onhashchange does not trigger on page change", function() {
|
o("onhashchange does not trigger on page change", function() {
|
||||||
$window.onhashchange = o.spy()
|
$window.onhashchange = o.spy()
|
||||||
$window.location.href = "http://localhost/a"
|
$window.location.href = "http://localhost/a"
|
||||||
|
|
||||||
o($window.onhashchange.callCount).equals(0)
|
o($window.onhashchange.callCount).equals(0)
|
||||||
})
|
})
|
||||||
o("onhashchange does not trigger on page change with different hash", function() {
|
o("onhashchange does not trigger on page change with different hash", function() {
|
||||||
$window.location.href = "http://localhost/#a"
|
$window.location.href = "http://localhost/#a"
|
||||||
$window.onhashchange = o.spy()
|
$window.onhashchange = o.spy()
|
||||||
$window.location.href = "http://localhost/a#b"
|
$window.location.href = "http://localhost/a#b"
|
||||||
|
|
||||||
o($window.onhashchange.callCount).equals(0)
|
o($window.onhashchange.callCount).equals(0)
|
||||||
})
|
})
|
||||||
o("onhashchange does not trigger on page change with same hash", function() {
|
o("onhashchange does not trigger on page change with same hash", function() {
|
||||||
$window.location.href = "http://localhost/#b"
|
$window.location.href = "http://localhost/#b"
|
||||||
$window.onhashchange = o.spy()
|
$window.onhashchange = o.spy()
|
||||||
$window.location.href = "http://localhost/a#b"
|
$window.location.href = "http://localhost/a#b"
|
||||||
|
|
||||||
o($window.onhashchange.callCount).equals(0)
|
o($window.onhashchange.callCount).equals(0)
|
||||||
})
|
})
|
||||||
o("onhashchange triggers on history.back()", function() {
|
o("onhashchange triggers on history.back()", function() {
|
||||||
$window.location.href = "#a"
|
$window.location.href = "#a"
|
||||||
$window.onhashchange = o.spy()
|
$window.onhashchange = o.spy()
|
||||||
$window.history.back()
|
$window.history.back()
|
||||||
|
|
||||||
o($window.onhashchange.callCount).equals(1)
|
o($window.onhashchange.callCount).equals(1)
|
||||||
})
|
})
|
||||||
o("onhashchange triggers on history.forward()", function() {
|
o("onhashchange triggers on history.forward()", function() {
|
||||||
|
|
@ -470,7 +470,7 @@ o.spec("pushStateMock", function() {
|
||||||
$window.onhashchange = o.spy()
|
$window.onhashchange = o.spy()
|
||||||
$window.history.back()
|
$window.history.back()
|
||||||
$window.history.forward()
|
$window.history.forward()
|
||||||
|
|
||||||
o($window.onhashchange.callCount).equals(2)
|
o($window.onhashchange.callCount).equals(2)
|
||||||
})
|
})
|
||||||
o("onhashchange does not trigger on history.back() that causes page change with different hash", function() {
|
o("onhashchange does not trigger on history.back() that causes page change with different hash", function() {
|
||||||
|
|
@ -478,7 +478,7 @@ o.spec("pushStateMock", function() {
|
||||||
$window.location.href = "a#b"
|
$window.location.href = "a#b"
|
||||||
$window.onhashchange = o.spy()
|
$window.onhashchange = o.spy()
|
||||||
$window.history.back()
|
$window.history.back()
|
||||||
|
|
||||||
o($window.onhashchange.callCount).equals(0)
|
o($window.onhashchange.callCount).equals(0)
|
||||||
})
|
})
|
||||||
o("onhashchange does not trigger on history.back() that causes page change with same hash", function() {
|
o("onhashchange does not trigger on history.back() that causes page change with same hash", function() {
|
||||||
|
|
@ -486,7 +486,7 @@ o.spec("pushStateMock", function() {
|
||||||
$window.location.href = "a#a"
|
$window.location.href = "a#a"
|
||||||
$window.onhashchange = o.spy()
|
$window.onhashchange = o.spy()
|
||||||
$window.history.back()
|
$window.history.back()
|
||||||
|
|
||||||
o($window.onhashchange.callCount).equals(0)
|
o($window.onhashchange.callCount).equals(0)
|
||||||
})
|
})
|
||||||
o("onhashchange does not trigger on history.forward() that causes page change with different hash", function() {
|
o("onhashchange does not trigger on history.forward() that causes page change with different hash", function() {
|
||||||
|
|
@ -495,7 +495,7 @@ o.spec("pushStateMock", function() {
|
||||||
$window.onhashchange = o.spy()
|
$window.onhashchange = o.spy()
|
||||||
$window.history.back()
|
$window.history.back()
|
||||||
$window.history.forward()
|
$window.history.forward()
|
||||||
|
|
||||||
o($window.onhashchange.callCount).equals(0)
|
o($window.onhashchange.callCount).equals(0)
|
||||||
})
|
})
|
||||||
o("onhashchange does not trigger on history.forward() that causes page change with same hash", function() {
|
o("onhashchange does not trigger on history.forward() that causes page change with same hash", function() {
|
||||||
|
|
@ -504,7 +504,7 @@ o.spec("pushStateMock", function() {
|
||||||
$window.onhashchange = o.spy()
|
$window.onhashchange = o.spy()
|
||||||
$window.history.back()
|
$window.history.back()
|
||||||
$window.history.forward()
|
$window.history.forward()
|
||||||
|
|
||||||
o($window.onhashchange.callCount).equals(0)
|
o($window.onhashchange.callCount).equals(0)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
@ -512,45 +512,45 @@ o.spec("pushStateMock", function() {
|
||||||
o("onunload triggers on location.href change", function() {
|
o("onunload triggers on location.href change", function() {
|
||||||
$window.onunload = o.spy()
|
$window.onunload = o.spy()
|
||||||
$window.location.href = "http://localhost/a"
|
$window.location.href = "http://localhost/a"
|
||||||
|
|
||||||
o($window.onunload.callCount).equals(1)
|
o($window.onunload.callCount).equals(1)
|
||||||
o($window.onunload.args[0].type).equals("unload")
|
o($window.onunload.args[0].type).equals("unload")
|
||||||
})
|
})
|
||||||
o("onunload triggers on relative location.href change", function() {
|
o("onunload triggers on relative location.href change", function() {
|
||||||
$window.onunload = o.spy()
|
$window.onunload = o.spy()
|
||||||
$window.location.href = "a"
|
$window.location.href = "a"
|
||||||
|
|
||||||
o($window.onunload.callCount).equals(1)
|
o($window.onunload.callCount).equals(1)
|
||||||
})
|
})
|
||||||
o("onunload triggers on search change via location.href", function() {
|
o("onunload triggers on search change via location.href", function() {
|
||||||
$window.onunload = o.spy()
|
$window.onunload = o.spy()
|
||||||
$window.location.href = "http://localhost/?a"
|
$window.location.href = "http://localhost/?a"
|
||||||
|
|
||||||
o($window.onunload.callCount).equals(1)
|
o($window.onunload.callCount).equals(1)
|
||||||
})
|
})
|
||||||
o("onunload triggers on relative search change via location.href", function() {
|
o("onunload triggers on relative search change via location.href", function() {
|
||||||
$window.onunload = o.spy()
|
$window.onunload = o.spy()
|
||||||
$window.location.href = "?a"
|
$window.location.href = "?a"
|
||||||
|
|
||||||
o($window.onunload.callCount).equals(1)
|
o($window.onunload.callCount).equals(1)
|
||||||
})
|
})
|
||||||
o("onunload does not trigger on hash change via location.href", function() {
|
o("onunload does not trigger on hash change via location.href", function() {
|
||||||
$window.onunload = o.spy()
|
$window.onunload = o.spy()
|
||||||
$window.location.href = "http://localhost/#a"
|
$window.location.href = "http://localhost/#a"
|
||||||
|
|
||||||
o($window.onunload.callCount).equals(0)
|
o($window.onunload.callCount).equals(0)
|
||||||
})
|
})
|
||||||
o("onunload does not trigger on relative hash change via location.href", function() {
|
o("onunload does not trigger on relative hash change via location.href", function() {
|
||||||
$window.onunload = o.spy()
|
$window.onunload = o.spy()
|
||||||
$window.location.href = "#a"
|
$window.location.href = "#a"
|
||||||
|
|
||||||
o($window.onunload.callCount).equals(0)
|
o($window.onunload.callCount).equals(0)
|
||||||
})
|
})
|
||||||
o("onunload does not trigger on hash-only history.back()", function() {
|
o("onunload does not trigger on hash-only history.back()", function() {
|
||||||
$window.location.href = "#a"
|
$window.location.href = "#a"
|
||||||
$window.onunload = o.spy()
|
$window.onunload = o.spy()
|
||||||
$window.history.back()
|
$window.history.back()
|
||||||
|
|
||||||
o($window.onunload.callCount).equals(0)
|
o($window.onunload.callCount).equals(0)
|
||||||
})
|
})
|
||||||
o("onunload does not trigger on hash-only history.forward()", function() {
|
o("onunload does not trigger on hash-only history.forward()", function() {
|
||||||
|
|
@ -558,7 +558,7 @@ o.spec("pushStateMock", function() {
|
||||||
$window.history.back()
|
$window.history.back()
|
||||||
$window.onunload = o.spy()
|
$window.onunload = o.spy()
|
||||||
$window.history.forward()
|
$window.history.forward()
|
||||||
|
|
||||||
o($window.onunload.callCount).equals(0)
|
o($window.onunload.callCount).equals(0)
|
||||||
})
|
})
|
||||||
o("onunload has correct url during call via location.href change", function(done) {
|
o("onunload has correct url during call via location.href change", function(done) {
|
||||||
|
|
@ -576,4 +576,4 @@ o.spec("pushStateMock", function() {
|
||||||
$window.location.search = "?a"
|
$window.location.search = "?a"
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ o.spec("xhrMock", function() {
|
||||||
o.beforeEach(function() {
|
o.beforeEach(function() {
|
||||||
$window = xhrMock()
|
$window = xhrMock()
|
||||||
})
|
})
|
||||||
|
|
||||||
o.spec("xhr", function() {
|
o.spec("xhr", function() {
|
||||||
o("works", function(done, timeout) {
|
o("works", function(done, timeout) {
|
||||||
$window.$defineRoutes({
|
$window.$defineRoutes({
|
||||||
|
|
@ -81,13 +81,13 @@ o.spec("xhrMock", function() {
|
||||||
return {status: 200, responseText: queryData["callback"] + "(" + JSON.stringify({a: 1}) + ")"}
|
return {status: 200, responseText: queryData["callback"] + "(" + JSON.stringify({a: 1}) + ")"}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
$window["cb"] = finish
|
$window["cb"] = finish
|
||||||
|
|
||||||
var script = $window.document.createElement("script")
|
var script = $window.document.createElement("script")
|
||||||
script.src = "/test?callback=cb"
|
script.src = "/test?callback=cb"
|
||||||
$window.document.documentElement.appendChild(script)
|
$window.document.documentElement.appendChild(script)
|
||||||
|
|
||||||
function finish(data) {
|
function finish(data) {
|
||||||
o(data).deepEquals({a: 1})
|
o(data).deepEquals({a: 1})
|
||||||
done()
|
done()
|
||||||
|
|
@ -101,13 +101,13 @@ o.spec("xhrMock", function() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
$window.$defineJSONPCallbackKey("cb")
|
$window.$defineJSONPCallbackKey("cb")
|
||||||
|
|
||||||
$window["customcb"] = finish2
|
$window["customcb"] = finish2
|
||||||
|
|
||||||
var script = $window.document.createElement("script")
|
var script = $window.document.createElement("script")
|
||||||
script.src = "/test?cb=customcb"
|
script.src = "/test?cb=customcb"
|
||||||
$window.document.documentElement.appendChild(script)
|
$window.document.documentElement.appendChild(script)
|
||||||
|
|
||||||
function finish2(data) {
|
function finish2(data) {
|
||||||
o(data).deepEquals({a: 2})
|
o(data).deepEquals({a: 2})
|
||||||
done()
|
done()
|
||||||
|
|
@ -120,13 +120,13 @@ o.spec("xhrMock", function() {
|
||||||
return {status: 200, responseText: queryData["callback"] + "(" + JSON.stringify({a: 3}) + ")"}
|
return {status: 200, responseText: queryData["callback"] + "(" + JSON.stringify({a: 3}) + ")"}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
$window["cbwithinparams"] = finish
|
$window["cbwithinparams"] = finish
|
||||||
|
|
||||||
var script = $window.document.createElement("script")
|
var script = $window.document.createElement("script")
|
||||||
script.src = "/test?a=b&callback=cbwithinparams&c=d"
|
script.src = "/test?a=b&callback=cbwithinparams&c=d"
|
||||||
$window.document.documentElement.appendChild(script)
|
$window.document.documentElement.appendChild(script)
|
||||||
|
|
||||||
function finish(data) {
|
function finish(data) {
|
||||||
o(data).deepEquals({a: 3})
|
o(data).deepEquals({a: 3})
|
||||||
done()
|
done()
|
||||||
|
|
@ -137,11 +137,11 @@ o.spec("xhrMock", function() {
|
||||||
script.onerror = finish
|
script.onerror = finish
|
||||||
script.src = "/test?cb=nonexistent"
|
script.src = "/test?cb=nonexistent"
|
||||||
$window.document.documentElement.appendChild(script)
|
$window.document.documentElement.appendChild(script)
|
||||||
|
|
||||||
function finish(e) {
|
function finish(e) {
|
||||||
o(e.type).equals("error")
|
o(e.type).equals("error")
|
||||||
done()
|
done()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ module.exports = function() {
|
||||||
var serverErrorHandler = function() {
|
var serverErrorHandler = function() {
|
||||||
return {status: 500, responseText: "server error, most likely the URL was not defined"}
|
return {status: 500, responseText: "server error, most likely the URL was not defined"}
|
||||||
}
|
}
|
||||||
|
|
||||||
var $window = {
|
var $window = {
|
||||||
XMLHttpRequest: function XMLHttpRequest() {
|
XMLHttpRequest: function XMLHttpRequest() {
|
||||||
var args = {}
|
var args = {}
|
||||||
|
|
@ -74,4 +74,4 @@ module.exports = function() {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return $window
|
return $window
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,4 +5,4 @@ module.exports = function(store) {
|
||||||
if (arguments.length > 0) store = arguments[0]
|
if (arguments.length > 0) store = arguments[0]
|
||||||
return store
|
return store
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
<script src="../../util/withAttr.js"></script>
|
<script src="../../util/withAttr.js"></script>
|
||||||
<script src="test-prop.js"></script>
|
<script src="test-prop.js"></script>
|
||||||
<script src="test-withAttr.js"></script>
|
<script src="test-withAttr.js"></script>
|
||||||
|
|
||||||
<script>require("../../ospec/ospec").run()</script>
|
<script>require("../../ospec/ospec").run()</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,8 @@ o.spec("prop", function() {
|
||||||
var initialValue = store()
|
var initialValue = store()
|
||||||
store(2)
|
store(2)
|
||||||
var newValue = store()
|
var newValue = store()
|
||||||
|
|
||||||
o(initialValue).equals(1)
|
o(initialValue).equals(1)
|
||||||
o(newValue).equals(2)
|
o(newValue).equals(2)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ o.spec("withAttr", function() {
|
||||||
handler: withAttr("value", spy)
|
handler: withAttr("value", spy)
|
||||||
}
|
}
|
||||||
context.handler({currentTarget: {value: 1}})
|
context.handler({currentTarget: {value: 1}})
|
||||||
|
|
||||||
o(spy.args).deepEquals([1])
|
o(spy.args).deepEquals([1])
|
||||||
o(spy.this).equals(context)
|
o(spy.this).equals(context)
|
||||||
})
|
})
|
||||||
|
|
@ -23,7 +23,7 @@ o.spec("withAttr", function() {
|
||||||
handler: withAttr("readonly", spy)
|
handler: withAttr("readonly", spy)
|
||||||
}
|
}
|
||||||
context.handler({currentTarget: target})
|
context.handler({currentTarget: target})
|
||||||
|
|
||||||
o(spy.args).deepEquals(["readonly"])
|
o(spy.args).deepEquals(["readonly"])
|
||||||
o(spy.this).equals(context)
|
o(spy.this).equals(context)
|
||||||
})
|
})
|
||||||
|
|
@ -32,7 +32,7 @@ o.spec("withAttr", function() {
|
||||||
var context = {}
|
var context = {}
|
||||||
var handler = withAttr("value", spy, context)
|
var handler = withAttr("value", spy, context)
|
||||||
handler({currentTarget: {value: 1}})
|
handler({currentTarget: {value: 1}})
|
||||||
|
|
||||||
o(spy.this).equals(context)
|
o(spy.this).equals(context)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -4,4 +4,4 @@ module.exports = function(attrName, callback, context) {
|
||||||
return function(e) {
|
return function(e) {
|
||||||
return callback.call(context || this, attrName in e.currentTarget ? e.currentTarget[attrName] : e.currentTarget.getAttribute(attrName))
|
return callback.call(context || this, attrName in e.currentTarget ? e.currentTarget[attrName] : e.currentTarget.getAttribute(attrName))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue