- Suggested Setup
- When evaluating an expression
- Have a good pattern?
Example implementation of these testing patterns
####Suggested Filter Unit Test Setup ↑
# CoffeeScript
describe 'Service: myFltr', ->
myFltr = null
beforeEach ->
# Load the filters's module
module 'myApp'
# Provide any mocks needed
module ($provide) ->
#$provide.value 'Name', new MockName()
# Make sure CoffeeScript doesn't return anything
null
# Inject in angular constructs otherwise,
# you would need to inject these into each test
inject ($filter) ->
myFltr = $filter('myFltr')
it 'should exist', ->
expect(!!myFltr).toBe yes
describe 'when evaluating an expression', ->
# Add specs
// JavaScript
describe('Filter: myFltr', function () {
var myFltr;
beforeEach(function () {
// Load the filters's module
module('myApp');
// Provide any mocks needed
module(function ($provide) {
//$provide.value('Name', new MockName());
});
// Inject in angular constructs otherwise,
// you would need to inject these into each test
inject(function ($filter) {
myFltr = $filter('myFltr');
});
});
it('should exist', function () {
expect(!!myFltr).toBe(true);
});
describe('when evaluating an expression', function () {
// Add specs
});
});
#####return the expected output ↑
# CoffeeScript
it 'should return the expected output', ->
text = 'AngularJS'
expect(myFltr(text)).toBe "my filter: #{text}"
// JavaScript
it('should return the expected output', function () {
var text = 'AngularJS';
expect(myFltr(text)).toBe('my filter: ' + text);
});