● Executes in-browser
○ Execute tests from anywhere
● Open source : http://bobbuzz.me.uk/2bVjTEr
● Minor changes for locker service
● Behaviour-driven development testing framework
○ Given the job page is open
When the user searches for jobs
Then the search method should be invoked
● Also known as Setup (Given) - Exercise (When) - Verify (Then)
○ Collection of tests
○ describe function
○ Single test
○ it function
○ Verifies behaviour (equivalent of assert in Apex)
○ expect function
○ Chained with matcher function
○ beforeAll - called once, before first spec
○ afterAll - called once, after last spec
○ beforeEach - called before each spec
○ afterEach - called after each spec
○ Stubs function
○ Tracks calls
○ Tracks arguments
Reset when spec/suite completes
server side action
spy on the getJobs function
Jasmine spy code replaces getJobs
implementation - no server side action
interrogate spy to confirm behaviour
● Object with functions to handle Jasmine events
○ e.g. JasmineStarted, specStarted, specDone
● HTML reporter included
○ Disabled in the github repository
○ Replaced with SLDS version
● Console reporter available
○ But deprecated!
1. The test application creates the Jasmine instance
The Jasmine instance is visible to all components in the same namespace.
This includes all testable components.
2. The application fires an event asking the reporters to initialize
This is an application event that can be received by any component with an
3. Each reporter registers an object to receive notifications with Jasmine
The object can take action on each event, but my samples simply capture the
information as the tests progress and then take action once all are complete.
4. Each reporter fires an event to indicate it has completed initialization
5. Once all reporters have initialised, the application fires a queue tests event
The application knows how many responses to expect.
6. Each testable component receives the event and queues their tests with Jasmine
The tests are not run at this point!
7. Each testable component fires an event to indicate it has queued its tests
The test application knows how many responses to expect.
8. The test application invokes the Jasmine execute method
This executes the queued tests
9. As tests execute, they notify the reporter(s) of the outcomes
The sample reporters record this information but take no action
10. The application notifies the reporter(s) that all tests are complete
The sample reporters take appropriate action once all tests are complete.
Posting to chatter, for example.
● Front end code deserves unit tests
● Decompose functions
● Isolate framework calls
● It's probably not the locker service!