【发布时间】:2013-06-27 11:31:18
【问题描述】:
我有一个基本模型,我正在尝试为其编写一个简单的单元测试套件,但我显然遗漏了一些东西......
模型的代码如下所示:
angular.module('AboutModel', [])
.factory(
'AboutModel',
[
function () {
var paragraphs = [];
var AboutModel = {
setParagraphs: function (newParagraphs) {
paragraphs = newParagraphs;
},
getParagraphs: function () {
return paragraphs;
}
};
return AboutModel;
}
]
);
要求很简单:为名为@987654323@的私有数组提供getter和setter方法。
这是我所获得的测试套件代码:
describe('Testing AboutModel:', function () {
describe('paragraphs setter', function () {
beforeEach(module('AboutModel'));
it('sets correct value', inject(function (model) {
// STUCK HERE
// don't know how to access the model, or the setParagraphs() method
}));
});
describe('paragraphs getter', function () {
// not implemented yet
});
});
我已经在网络上做了大量的谷歌研究,但到目前为止还没有任何乐趣。
解决方案必须简单;请帮忙!
甚至可能有更好的方法来实现模型...欢迎提出建议以使其变得更好。
对于任何感兴趣的人,完整的源代码在这里: https://github.com/mcalthrop/profiles/tree/imp/angular
提前致谢
马特
【问题讨论】:
标签: unit-testing angularjs jasmine karma-runner