Spoke is an application for ServiceNow that lets you run JavaScript specifications for behavior-driven development (BDD).
Spoke has an interactive, user friendly interface which means running tests in ServiceNow is really easy. Literally, anyone can use it. Validate releases simply by going into Spoke and clicking one button. You really can forget about using fix scripts for testing!
When you start writing BDD tests, you are automatically building an API documentation for your code. As long as you keep your tests up to date, you've got living documentation and proof that your code does what it's supposed to do all in one. What's not to like?
If you're testing, you want errors to be abundantly clear. Not only does Spoke capture the test failures, it will also capture errors with your script (unless you somehow manage to kill the thread).
If you've ever used the popular Jasmine framework, then you're ready to go. Spoke uses a version of Jasmine that has been rebuilt from the ground up to work natively in ServiceNow.
Spoke can run tests in scoped applications as long as the scripts are globally accessible.
Get the full test output as JSON for one or all the tests using a simple HTTP request.
Spoke comes packaged with core Jasmine tests† so you can see for yourself what it can do.
†: Does not include tests for as yet unsupported functionality such as spies.
Install it, and then…
- Create a script include with _spec appended to the name†. This is how Spoke will find your test specifications.
- Create a new suite and write about what your code does and the expectations you have. This is the hardest bit to learn how to do well if you're new to BDD.
describe('MyClass', function () { it('does some cool stuff', function () { expect('cool stuff').not.toBe('uncool stuff'); }); });
- Execute the specification in Spoke.
† If you are writing a specification for a script include, simply use the same name plus '_spec'. You don't have to do this, but it will make your life easier. E.g. 'MyClass' -> 'MyClass_spec'
- Append ?sys_scope=your scope name to the URL. Spoke will then scan for Script Includes belonging to that application scope that in _spec.
- Test away!
- From the Spoke interface, locate the spec you want to test.
- Right click on the Execute button and open it in a new window.
- You'll see JSON output for your test that you can plug into a tool by copying the URL.
Not everything that you can do with Jasmine can be done with Spoke, mainly due to the limitations of running on a server architecture instead of a browser. Other stuff has just been skipped for the time being.
- Suite definition
- describe
- xdescribe
- Specification definition
- it
- xit
- beforeAll
- beforeEach
- afterAll
- afterEach
- expect
- Expectation Matchers
- toBe
- toEqual
- toMatch
- toBeDefined
- toBeUndefined
- toBeNull
- toBeTruthy
- toBeFalsy
- toContain
- toBeLessThan
- toBeGreaterThan
- toBeCloseTo
- toThrow
- toThrowError
- not.*
- Other
- fail
- Jasmine: jasmine / jasmine