9

I have an Ember EAK project migrated to Ember CLI, with tests coded for mocha/chai test runner which don't run correctly in the migrated project, even though I've installed ember-cli-mocha. Can I use 'ember generate', with the mocha blueprints, to generate new test stubs where I can then go in and more or less re-implement what I had with the tests in EAK?

So I want to use 'ember generate' to generate tests for existing routes, controllers & views, rather than generating new stub objects and tests together.

bobvan
  • 251
  • 3
  • 9

2 Answers2

8

Yes, you can indeed do this, using the ember generate blueprints of controller-test, route-test, etc.

ember generate controller-test my-resource

This is documented at http://www.ember-cli.com/#appendix. This is an ember-cli feature, not an ember feature, so is covered in the documentation for the former. Additional information can be obtained with ember generate help.

  • If there's a doc on ember generate, I can't find it. The 'testing' sections don't cover it. 'generated objects' doesn't cover it (http://guides.emberjs.com/v1.10.0/routing/generated-objects/). 'testing controllers' doesn't cover it (http://guides.emberjs.com/v1.10.0/testing/testing-controllers/). But I can do some trial and error and maybe figure out the CLI syntax by sticking '-test' at the end to see if I can create a test stub for a particular 'object'. thx – bobvan Jun 20 '15 at 15:53
  • Is there anything that generates stuff more than stubs? – Nikos Jun 20 '17 at 12:50
  • I can't find the doc either – Nikos Jun 20 '17 at 12:51
6

Try the following

ember g component-test component-module-name ember g component-test component-module-name --unit

ember g component-test --help

Shows

ember generate <blueprint> <options...>
  Generates new code from blueprints.
  aliases: g
  --dry-run (Boolean) (Default: false)
    aliases: -d
  --verbose (Boolean) (Default: false)
    aliases: -v
  --pod (Boolean) (Default: false)
    aliases: -p
  --classic (Boolean) (Default: false)
    aliases: -c
  --dummy (Boolean) (Default: false)
    aliases: -dum, -id
  --in-repo-addon (String) (Default: null)
    aliases: --in-repo <value>, -ir <value>

      component-test <name> <options...>
        Generates a component integration or unit test.
        --test-type (integration, unit) (Default: integration)
          aliases: -i (--test-type=integration), -u (--test-type=unit), --integration (--test-type=integration), -unit (--test-type=unit)
Alan Dong
  • 3,981
  • 38
  • 35