All Projects β†’ Profiscience β†’ ko-component-tester

Profiscience / ko-component-tester

Licence: other
🚦 TDD Helpers for Knockout JS

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to ko-component-tester

Cqrs Clean Eventual Consistency
CQRS, using Clean Architecture, multiple databases and Eventual Consistency
Stars: ✭ 247 (+1546.67%)
Mutual labels:  tdd
svut
SVUT is a simple framework to create Verilog/SystemVerilog unit tests. Just focus on your tests!
Stars: ✭ 48 (+220%)
Mutual labels:  tdd
goss
Quick and Easy server testing/validation
Stars: ✭ 26 (+73.33%)
Mutual labels:  tdd
Jasmine
Simple JavaScript testing framework for browsers and node.js
Stars: ✭ 15,261 (+101640%)
Mutual labels:  tdd
chai
BDD / TDD assertion framework for node.js and the browser that can be paired with any testing framework.
Stars: ✭ 7,842 (+52180%)
Mutual labels:  tdd
finance-project-ddd
Projeto financeiro usando domain driven design, tdd, arquitetura hexagonal e solid
Stars: ✭ 67 (+346.67%)
Mutual labels:  tdd
Nspec
A battle hardened testing framework for C# that's heavily inspired by Mocha and RSpec.
Stars: ✭ 242 (+1513.33%)
Mutual labels:  tdd
eye drops
Configurable Elixir mix task to watch file changes and run the corresponding command.
Stars: ✭ 51 (+240%)
Mutual labels:  tdd
chai-exclude
Exclude keys to compare from a deep equal operation with chai expect or assert.
Stars: ✭ 33 (+120%)
Mutual labels:  tdd
Examin
Examin is a developer tool that generates React unit tests for your application. Ensure your application renders as expected before adding new features. Examin writes the baseline unit tests and allows developers to customize their tests for their application.
Stars: ✭ 75 (+400%)
Mutual labels:  tdd
TDD
Everything about testing, especially TDD, Test-Driven Development: Really, It’s a Design Technique
Stars: ✭ 28 (+86.67%)
Mutual labels:  tdd
Unmockable
πŸ’‰ β†ͺ️ 🎁 Unmockable objects wrapping in .NET
Stars: ✭ 35 (+133.33%)
Mutual labels:  tdd
memo
λ‹€μ–‘ν•œ MD λ©”λͺ¨
Stars: ✭ 87 (+480%)
Mutual labels:  tdd
Silsilah
A genealogy/family tree application, built with Laravel.
Stars: ✭ 246 (+1540%)
Mutual labels:  tdd
mugshot
Framework independent visual testing library
Stars: ✭ 126 (+740%)
Mutual labels:  tdd
Alsatian
TypeScript testing framework with test cases
Stars: ✭ 244 (+1526.67%)
Mutual labels:  tdd
knockout-decorators
Decorators for use Knockout JS in TypeScript and ESNext environments
Stars: ✭ 45 (+200%)
Mutual labels:  knockoutjs
doctest
The fastest feature-rich C++11/14/17/20 single-header testing framework
Stars: ✭ 4,434 (+29460%)
Mutual labels:  tdd
bitwig
Some controller scripts for Bitwig
Stars: ✭ 43 (+186.67%)
Mutual labels:  knockoutjs
my-react-todolist
A guide to TDD a React/Redux TodoList App
Stars: ✭ 22 (+46.67%)
Mutual labels:  tdd

ko-component-tester

NPM WTFPL Travis Coverage Status Dependency Status Peer Dependency Status NPM Downloads

TDD Helpers for Knockout components and bindings

Sample tests for a Knockout binding

'use strict'

const { renderHtml } = require('ko-component-tester')
const { expect } = require('chai')

describe ('Hello World text-binding', () => {
  let $el
  beforeEach(() => {
    $el = renderHtml({
      template: `<div data-bind="text: greeting"></div>`,
      viewModel: { greeting: 'Hello World'}
      })
  })
  it('renders', () => {
    expect($el).to.exist
  })
  it('renders correct text', () => {
    expect($el.html()).equals('Hello World')
  })
})

Sample tests for a Knockout component

'use strict'

const { renderComponent } = require('ko-component-tester')
const { expect } = require('chai')

describe('Hello World Component' , () => {
  let $el
  beforeEach(() => {
    $el = renderComponent({
      template: `<span data-bind="text: greeting"></span>`,
      viewModel: function() { this.greeting = 'Hello World' }
    })
  })
  afterEach(() => {
    $el.dispose()
  })
  it('renders', () => {
    expect($el).to.exist
  })
  it('renders correct content', () => {
    expect($el.html()).contains('Hello World')
  })
})

Sample Login test

'use strict'

const ko = require('knockout')
const { expect } = require('chai')
const sinon = require('sinon')
const { renderComponent } = require('../src')

class LoginComponent {
  constructor() {
    this.username = ko.observable()
    this.password = ko.observable()
  }
  submit() {}
}

describe('sample login component' , () => {
  let $el

  before(() => {
    $el = renderComponent({
      viewModel: LoginComponent,
      template: `
        <form data-bind="submit: submit">
          <input name="user" type="text" data-bind="value: username">
          <input name="pass" type="text" data-bind="value: password">
          <input type="submit">
        </form>`
    })
  })

  after(() => {
    $el.dispose()
  })

  it('renders correctly', () => {
    expect($el).to.exist
    expect($el.find('form'), 'contains a form').to.exist
    expect($el.find('input[name="user"]', 'contains a username field')).to.exist
    expect($el.find('input[name="pass"]', 'contains a password field')).to.exist
    expect($el.find('input[type="submit"]', 'contains a submit button')).to.exist
  })

  it('updates the viewmodel when a value is changed', () => {
    $el.find('input[name=user]').simulate('change', 'john')
    expect($el.$data().username()).equals('john')
  })

  it('can submit the form', () => {
    const submitSpy = sinon.spy($el.$data().submit)
    $el.find('input[name=user]').simulate('change', 'john')
    $el.find('input[name=pass]').simulate('change', 'p455w0rd')
    $el.find('input[type="submit"]').simulate('click')

    expect(submitSpy).to.be.called
  })
})

renderHtml(options)

returns a jQuery element containing the rendered html output

  • options.template - a string of html to be rendered
  • options.viewModel - an object, function, or class

Example with viewModel function:

const options = {
  template: `<div data-bind="text: greeting"></div>`,
  viewModel: function() { this.greeting = 'Hello Text Binding' }
}
const $el = renderHtml(options)

Example with viewModel class:

const options = {
  template: `<div data-bind="text: greeting"></div>`,
  viewModel: class ViewModel {
    constructor() {
      this.greeting = 'Hello Text Binding'
    }
  }
}
const $el = renderHtml(options)

Example with viewModel object:

const options = {
  template: `<div data-bind="text: greeting"></div>`,
  viewModel: { greeting: 'Hello Text Binding' }
}
const $el = renderHtml(options)

See spec for more examples of renderHtml().

renderComponent(component, params, bindingContext)

returns a jQuery element containing the rendered html output

  • component.template - a string of html to be rendered
  • component.viewModel - a function, class, or instance
  • params - optional params to be passed into the viewModel's constructor
  • bindingContext - optional bindingContext to inject (useful for stubbing $parent or $index)

Example with viewModel function:

const component = {
  template: `<div data-bind="text: greeting"></div>`,
  viewModel: function() { this.greeting = 'Hello Text Binding' }
}
const $el = renderComponent(component)
// $el.dispose()

Example with viewModel class:

const component = {
  template: `<div data-bind="text: greeting"></div>`,
  viewModel: class ViewModel {
    constructor(params) {
      this.greeting = params.greeting
    }
  }
}
const params = {
  greeting: 'Hello Text Binding'
}
const $el = renderComponent(component, params)
// $el.dispose()

Example with viewModel instance:

class ViewModel {
  constructor(params) {
    this.greeting = params.greeting
  }
}
const component = {
  template: `<div data-bind="text: greeting"></div>`,
  viewModel: { instance: new ViewModel(params) }
}
const $el = renderComponent(component)
// $el.dispose()

See spec for more examples of renderComponent().

$el.getComponentParams()

see spec for examples

$el.waitForBinding()

see spec for examples

$el.waitForProperty()

see spec for examples

$el.simulate(event, value)

  • event - the event to simulate, eg 'click', or 'change'
  • value - if provided this value will be assigned. It's handy for assigning a value to a textbox and triggering a change event like this.
// simulate changing the value of a textbox
$input.simulate('change', 'new value')
// simulate clicking a button
$submit.simulate('click')

Attribution

https://github.com/jeremija/kotest

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].