Journey to the Center of Ember Test Helpers

Post on 20-Jan-2017

262 views 0 download

Transcript of Journey to the Center of Ember Test Helpers

Journey to the Center of

Ember Test

Helpers

Liz Baillie @infinite_math

Abandon All Hope, Ye Who Enter

Here

A LOT OF SOURCE

CODE!!11!

me (Liz)

Rails + Ember =

<3

Rust :)

Liz Baillie

Ember Wildlife Adventure ExpertTomster Specialist Level Zero

cryptotomsterology

* not a real thing

Liz Baillie

Ember Wildlife Adventure ExpertTomster Specialist Level Zero

cryptotomsterology

TOMSTER

ember test

ember test

How an Ember CLI command is run

• lookupCommand() looks up the command we pass to it using findCommand()

• the findCommand() method (which is in lookup-command.js) validates the command and returns it if it’s all good

• if a core command is overwritten by this, an error is thrown, but we we still return it (I think)

How an Ember CLI command is run

• lookupCommand() looks up the command we pass to it using findCommand()

• the findCommand() method (which is in lookup-command.js) validates the command and returns it if it’s all good

• if a core command is overwritten by this, an error is thrown, but we we still return it (I think)

How an Ember CLI command is run

• lookupCommand() looks up the command we pass to it using findCommand()

• the findCommand() method (which is in lookup-command.js) validates the command and returns it if it’s all good

• if a core command is overwritten by this, an error is thrown, but we we still return it (I think)

~ ANYWAY ~

How lookupCommand calls the command

• required + used in cli.js

• before it’s run, we can pass in options to extend it

• validate the command in validateAndRun() + throw an error if needed

• otherwise, we run the command

How lookupCommand calls the command

• required + used in cli.js

• before it’s run, we can pass in options to extend it

• validate the command in validateAndRun() + throw an error if needed

• otherwise, we run the command

How lookupCommand calls the command

• required + used in cli.js

• before it’s run, we can pass in options to extend it

• validate the command in validateAndRun() + throw an error if needed

• otherwise, we run the command

How lookupCommand calls the command

• required + used in cli.js

• before it’s run, we can pass in options to extend it

• validate the command in validateAndRun() + throw an error if needed

• then, we run the command

How the ‘test’ task is run from the command

• the test task is built and run in the command

• testem is triggered from our ‘test’ task

• testem runs our tests!

How the ‘test’ task is run from the command

• the test task is built and run in the command

• testem is triggered from our ‘test’ task

• testem runs our tests!

How the ‘test’ task is run from the command

• the test task is built and run in the command

• testem is triggered from our ‘test’ task

• testem runs our tests!

• come with Ember out of the box

What do we know about Ember’s test helpers?

• come with Ember out of the box

• can only use on acceptance tests

What do we know about Ember’s test helpers?

• come with Ember out of the box

• can only use on acceptance tests

• some are asynchronous

What do we know about Ember’s test helpers?

• come with Ember out of the box

• can only use on acceptance tests

• some are asynchronous

• some are synchronous

What do we know about Ember’s test helpers?

• come with Ember out of the box

• can only use on acceptance tests

• some are asynchronous

• some are synchronous

• andThen() - our one ‘wait’ helper

What do we know about Ember’s test helpers?

• they are maybe all about to

change?

What do we know about Ember’s test helpers?

~ ANYWAY ~

`registerAsyncHelper` is used to register an async test helper that will be injected when `App.injectTestHelpers` is called.

The helper method will always be called with the current Application as the first parameter.

`registerAsyncHelper` is used to register an async test helper that will be injected when `App.injectTestHelpers` is called.

This injects the test helpers into the `helperContainer` object.

‘If an object is provided it will be used as the helperContainer.’

“If ‘helperContainer’ is not set it will default to ‘window.’”

“If a function of the same name has already been defined it will be cached

(so it can be reset if the helper is removed with ‘unregisterHelper’ or ‘removeTestHelpers’)”

How test helpers get called

• test helpers are registered as either sync or async when they are called in a test

• before each test, the helpers are injected and then called

How test helpers get called

• test helpers are registered as either sync or async when they are called in a test

• before each test, the helpers are injected and then called

your name here

Ember Wildlife Adventure ExpertTomster Specialist Level Zero

cryptotomsterology

You are probably wondering things

• Why did we just do all that?

• Why would I ever want to that?

• It seems like you might have glossed over a bunch of stuff. Are you sure all that things you said were correct?

• Why did we just do all that?

• Why would I ever want to that?

• It seems like you might have glossed over a bunch of stuff. Are you sure all that things you said were correct?

• Why did we just do all that?

• Why would I ever want to that?

• It seems like you might have glossed over a bunch of stuff. Are you sure all that things you said were correct?

Why did we just do all that?

• we don’t HAVE TO do this

• anyone CAN do this, if they want

• not that scary!

• treat it like an adventure

• we don’t HAVE TO do this

• anyone CAN do this, if they want

• not that scary!

• treat it like an adventure

• we don’t HAVE TO do this

• anyone CAN do this, if they want

• not that scary!

• treat it like an adventure

• we don’t HAVE TO do this

• anyone CAN do this, if they want

• not that scary!

• treat it like an adventure

Why would I ever want to do that?

• Reading source code is a great learning experience

• better understanding of how things work under the hood

• can come in handy later on when debugging our tests

• anyone can do it

• Reading source code is a great learning experience

• better understanding of how things work under the hood

• can come in handy later on when debugging our tests

• anyone can do it

• Reading source code is a great learning experience

• better understanding of how things work under the hood

• can come in handy later on when debugging our tests

• anyone can do it

• Reading source code is a great learning experience

• better understanding of how things work under the hood

• can come in handy later on when debugging our tests

• anyone can do it

Was all that stuff correct?

• I don’t know, probably not all of it?

• pique your curiosity

• inspire you to read source code without intimidation

• I don’t know, probably not all of it?

• pique your curiosity

• inspire you to read source code without intimidation

• I don’t know, probably not all of it?

• pique your curiosity

• inspire you to read source code without intimidation

Resources• Ember CLI GitHub repo: https://github.com/ember-cli/ember-cli

• Ember CLI API docs: ember-cli.com/api

• Ember repo: https://github.com/emberjs/ember.js

• Ember API docs: emberjs.com/api

• Ember Community Slack for answers to your questions

Resources

• Robert Jackson’s Grand Testing Unification RFC: https://github.com/rwjblue/rfcs/blob/42/text/0000-grand-testing-unification.md

THANK YOULiz Baillie @infinite_math