fixing unit tests
This commit is contained in:
+29
-29
@@ -81,6 +81,8 @@ describe("Autocomplete controller", function() {
|
||||
user._id = "unique-user-id";
|
||||
|
||||
scope = $rootScope.$new();
|
||||
scope.group = {}
|
||||
scope.group.chat = [];
|
||||
|
||||
$controller = _$controller_;
|
||||
|
||||
@@ -91,39 +93,14 @@ describe("Autocomplete controller", function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe("chatChanged", function() {
|
||||
it('if a new chat arrives, the new user name is extracted', function() {
|
||||
|
||||
expect(scope.response.length).to.be.eq(0);
|
||||
expect(scope.usernames.length).to.be.eq(0);
|
||||
|
||||
scope.group = {}
|
||||
scope.group.chat = [{msg: "new chat", user: "boo"}];
|
||||
expect(scope.response.length).to.be.eq(0);
|
||||
expect(scope.usernames.length).to.be.eq(0);
|
||||
})
|
||||
});
|
||||
|
||||
describe("addNewUser", function() {
|
||||
it('a new message from a new user will modify the usernames', function() {
|
||||
expect(scope.response.length).to.be.eq(0);
|
||||
expect(scope.usernames.length).to.be.eq(0);
|
||||
|
||||
var msg = {user: "boo"};
|
||||
scope.addNewUser(msg);
|
||||
expect(scope.response[0]).to.be.eq(msg);
|
||||
expect(scope.usernames[0]).to.be.eq("boo");
|
||||
})
|
||||
})
|
||||
|
||||
describe("clearUserList", function() {
|
||||
it('calling the function clears the list of usernames and responses', function() {
|
||||
scope.response.push("blah");
|
||||
scope.usernames.push("blub");
|
||||
|
||||
scope.clearUserlist();
|
||||
expect(scope.response.length).to.be.eq(0); // to.be.empty() doesn't work for some reason. This is the same thing
|
||||
expect(scope.usernames.length).to.be.eq(0);
|
||||
expect(scope.response).to.be.empty; // to.be.empty() doesn't work for some reason. This is the same thing
|
||||
expect(scope.usernames).to.be.empty;
|
||||
})
|
||||
|
||||
it('the function is called upon initialization of the controller', function() {
|
||||
@@ -131,8 +108,8 @@ describe("Autocomplete controller", function() {
|
||||
scope.response.push("blub");
|
||||
ctrl = $controller('AutocompleteCtrl', {$scope: scope});
|
||||
|
||||
expect(scope.response.length).to.be.eq(0); // to.be.empty() doesn't work for some reason. This is the same thing
|
||||
expect(scope.usernames.length).to.be.eq(0);
|
||||
expect(scope.response).to.be.empty; // to.be.empty() doesn't work for some reason. This is the same thing
|
||||
expect(scope.usernames).to.be.empty;
|
||||
})
|
||||
})
|
||||
|
||||
@@ -161,4 +138,27 @@ describe("Autocomplete controller", function() {
|
||||
expect(scope.filterUser({user: "prefix"})).to.be.eq(false);
|
||||
})
|
||||
});
|
||||
|
||||
describe("addNewUser", function() {
|
||||
it('a new message from a new user will modify the usernames', function() {
|
||||
expect(scope.response).to.be.empty;
|
||||
expect(scope.usernames).to.be.empty;
|
||||
|
||||
var msg = {user: "boo"};
|
||||
scope.addNewUser(msg);
|
||||
expect(scope.response[0]).to.be.eq(msg);
|
||||
expect(scope.usernames[0]).to.be.eq("boo");
|
||||
});
|
||||
});
|
||||
|
||||
describe("chatChanged", function() {
|
||||
it('if a new chat arrives, the new user name is extracted', function() {
|
||||
var chatChanged = sinon.spy(scope, 'chatChanged');
|
||||
scope.$watch('group.chat',scope.chatChanged); // reinstantiate watch so spy works
|
||||
|
||||
scope.$digest(); // trigger watch
|
||||
scope.group.chat.push({msg: "new chat", user: "boo"});
|
||||
expect(chatChanged.callCount).to.be.eq(1);
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user