These are chat archives for canjs/canjs

18th
Feb 2015
Luis Merino
@Rendez
Feb 18 2015 20:21
@justinbmeyer I found easy to test can.js except components, because I am building a big template that contains multiple child components, and to test out some functionality it's hard to isolate a component.
Any advice you can give me to make testing easier?
Of course I could compose my own templates for each test so that I leave out other child components, but that would defeat the purpose because it would not be very maintenable and prone to errors (templates may differ from tests at some point)
Gerard Finnerty
@halcyonandon
Feb 18 2015 21:52
I used a lot of components within components. What problem are you having with testing them specifically? Every component would have a corresponding test suite... If you're writing modules, you're loading all subcomponents from the parent anyways. If your test is on the parent, there's no reason to test the functionality of the child components, even if they're included... components should be self-contained, so anything a child receives from a parent should be passed as arguments in the child's tag anyways...

describe('Some component', function( ) {

var $component;

beforeEach(function( done ) {
  System.import('shared/services/account/fixture').then(function( ) {
    Promise.all([
      System.import('can/util/can'),
      System.import('shared/components/forms/someComponent/someComponent'),
      System.import('can/view/stache')
    ]).then(function (values){
      var can  = values[0];

      var template = can.stache('<some-component/>');
      $('body').append(template());
      $component = $('some-component');

      done();
    });
  });
});

it('should have a scope', function() {
  expect($component.scope()).toBeDefined();
});

afterEach(function() {
  $component.remove();
});

});

That's a basic test setup of a component that checks for the scope, that's what I use in my yeoman generator for the component.test.js when generating a new component
I don't use funcunit though