[Unit Testing] Test Controller, summary unit testing
app.controller("AppCtrl",function(){
this.message = "hello";
})
describe("Hello Controller",function(){
var appCtrl;
var $controller;
beforeEach(module("app"))
beforeEach(inject(function(_$controller_){
$controller = _$controller_;
appCtrl = $controller("AppCtrl")
}))
describe("AppCtrl", function(){
it("Should have a message of hello",function(){
expect(appCtrl.message).toBe("hello");
})
})
})
In summary:
The code hierarchy should be something like:
describe("What is the test is", function () {
var $inject1,
$inject2;
beforeEach(module("app"))
beforeEach(inject(function (_$youwanttoinject1_, _$youwanttoinject2_) {
$inject1 = _$youwanttoinject1_
$inject2 = _$youwanttoinject2_
}))
describe("Describe the task",function(){
it("should be what",function(){
expect("what you expect").toBe("What it should be");
})
})
})

浙公网安备 33010602011771号