Skip to content

Commit

Permalink
pattern(constant): add initial testing patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
daniellmb committed Oct 2, 2013
1 parent 3e62612 commit 6f0edeb
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Angular Test Patterns [![Build Status](https://api.travis-ci.org/daniellmb/angular-test-patterns.png)](https://travis-ci.org/daniellmb/angular-test-patterns) [![Dependency Status](https://gemnasium.com/daniellmb/angular-test-patterns.png)](https://gemnasium.com/daniellmb/angular-test-patterns#tab-dev_dependencies)

High Quality Cut-n-Paste Guide for Testing your AngularJS [Controllers](patterns/controller.md), [Services](patterns/service.md), [Directives](patterns/directive.md) and [Filters](patterns/filter.md). As well as ideas on how to use [Mocks](patterns/mock.md), [End-to-End](patterns/e2e.md) tests, [Performance](patterns/performance.md) testing and [More](patterns/perceptualdiff.md)!
High Quality Cut-n-Paste Guide for Testing your AngularJS [Controllers](patterns/controller.md), [Services](patterns/service.md), [Constants](patterns/constant.md), [Directives](patterns/directive.md) and [Filters](patterns/filter.md). As well as ideas on how to use [Mocks](patterns/mock.md), [End-to-End](patterns/e2e.md) tests, [Performance](patterns/performance.md) testing and [More](patterns/perceptualdiff.md)!

## Testing Patterns

Expand Down
11 changes: 10 additions & 1 deletion example/coffeescript/app.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,13 @@ angular.module('myApp')

# return public API
getAPI()
]
]

###
Application Constants
----------------------
###

# Define My Constant
angular.module('myApp')
.constant 'myConst', 42
11 changes: 10 additions & 1 deletion example/javascript/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,13 @@ angular.module('myApp')
// return public API
return getAPI();
}
]);
]);

/*
Application Constants
----------------------
*/

// Define My Constant
angular.module('myApp')
.constant('myConst', 42);
78 changes: 78 additions & 0 deletions patterns/constant.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Unit Testing AngularJS Constants

##### Testing Patterns

* [Suggested Setup](#suggested-constant-unit-test-setup-)
* Patterns
* [be my expected value](#be-my-expected-value-)
* Have a good pattern?
* *[pull request welcome!](../#contributing-test-patterns)*

###### [Example](../example) implementation of these testing patterns

####Suggested Constant Unit Test Setup [↑](#testing-patterns)
```CoffeeScript
# CoffeeScript
describe 'Constant: myConst', ->
myConst = null

beforeEach ->
# Load the constant's module
module 'myApp'

# Inject in angular constructs otherwise,
# you would need to inject these into each test
inject (_myConst_) ->
myConst = _myConst_

it 'should exist', ->
expect(!!myConst).toBe yes

describe 'the constant', ->
# Add specs
```

```JavaScript
// JavaScript
describe('Constant: myConst', function () {
var myConst;

beforeEach(function () {
// Load the constant's module
module('myApp');

// Inject in angular constructs otherwise,
// you would need to inject these into each test
inject(function (_myConst_) {
myConst = _myConst_;
});
});

it('should exist', function () {
expect(!!myConst).toBe(true);
});

describe('the constant', function () {
// Add specs
});
});
```

####My constant should:

#####be my expected value [↑](#testing-patterns)
```CoffeeScript
# CoffeeScript
it 'should be my expected value', ->
expect(myConst).toBe(42)
```

```JavaScript
// JavaScript
it('should return my expected value', function () {
expect(myConst).toBe(42);
});
```



0 comments on commit 6f0edeb

Please sign in to comment.