@normanhaze wrote:
Has anybody had any success unit testing components using Mocha? I have some data transformation going on within the component and want to check that the individual functions are doing what they should.
I have successfully written some tests using this format:
import { expect } from 'chai'; import { describe, it } from 'mocha'; import { setupComponentTest } from 'ember-mocha'; describe('Unit | Component | my component', function() { setupComponentTest('my-component', { unit: true }); it('exists', function() { let component = this.subject(); expect(component).to.be.ok; }); });
However, I encounter a problem when trying to test a component which has an
init()
.init()
runs as soon as I callthis.subject()
, and therefore before I can set the props that it needs. My tests therefore error out as init doesn’t have the props it needs to run.Has anybody else run into similar problems? Component testing seems to be very much focussed on render testing, which seems odd when components can be used to manage chunks of logic, not just visuals.
Posts: 2
Participants: 2