profiscience / ko-component-tester Goto Github PK
View Code? Open in Web Editor NEW:vertical_traffic_light: TDD Helpers for Knockout JS
:vertical_traffic_light: TDD Helpers for Knockout JS
This file in /test
'use strict'
const { renderHtml } = require('ko-component-tester')
with the following package.json
{
"name": "knockout-tests",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha"
},
"author": "",
"license": "ISC",
"dependencies": {
"jquery": "^2.2.0",
"knockout": "^3.4.2",
"ko-component-tester": "^3.2.1"
}
}
gives errors
> [email protected] test /Users/sebs/projects/customers/sumcumo/knockout-tests
> mocha
/Users/sebs/projects/..../knockout-tests/node_modules/ko-component-tester/dist/ko-component-tester.js:67
$.fn.simulate = function (eventName, value) {
^
TypeError: Cannot set property 'simulate' of undefined
at Object.module.exports (....
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.runMain (module.js:590:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:509:3
One of the nice things about testing React components with Enzyme is that you can test your components as shallow. In this case, only the top level component gets rendered and all child components are ignored. This makes a lot of sense for unit testing, since you want to test your components as small, independent parts.
It would be nice if you could just call renderShallowComponent(...)
, but I'm guessing that would also be really involved. I can't say I have any idea how this would be implemented, maybe override the component binding somehow?
A simpler method would be an option to ignore certain components. So if you have a TodoList you could do:
renderComponent({
viewModel: TodoList,
template: todoListTemplate,
ignoreComponents: ['Todo']
})
These sub components would be registered as empty components. This is what I currently do in a before-call, but it would be tidier to have the functionality built in.
Thoughts?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.