0
Başımıza bir npm modülünü istiyorum (burada array-equal
Yasemin testlerinde npm modüllerini nasıl kullanırım?
basit bir örnek olarak bu benim yasemin testi Spec geçerli:
describe('BinoxxoController', function() {
beforeEach(angular.mock.module('binoxxoapp'));
beforeEach(inject(function(_$controller_) {
$controller = _$controller_;
}));
describe('$scope.lineIsValid', function() {
var $scope, controller;
beforeEach(function() {
$scope = {};
var controller = $controller('BinoxxoController', { $scope: $scope});
})
it('equals array', function() {
var array0 = [1, 2, 3];
var array1 = [1, 2, 3];
expect(equal(array0, array1)).toBe(true);
});
});
}); Eğer yardımcı olur
index.html (testrunner)
<!doctype html>
<html>
<head>
<title>Jasmine Spec Runner</title>
<link rel="stylesheet" href="../../../node_modules/jasmine-core/lib/jasmine-core/jasmine.css">
</head>
<body>
<script src="../../../node_modules/jasmine-core/lib/jasmine-core/jasmine.js"></script>
<script src="../../../node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js"></script>
<script src="../../../node_modules/jasmine-core/lib/jasmine-core/boot.js"></script>
<script src="../../../node_modules/angular/angular.js"></script>
<script src="../../../node_modules/angular-mocks/angular-mocks.js"></script>
<!-- include source files here... -->
<script src="../../../static/js/app.js"></script>
<script src="../../../node_modules/array-equal/index.js"></script>
<!-- include spec files here... -->
<script src="spec/controllerSpec.js"></script>
</body>
</html>
Ben modülü dahil, ama hala bir hata Burada ReferenceError: equal is not defined
olsun dizi-eşit modüldür:
module.exports = function equal(arr1, arr2) {
var length = arr1.length
if (length !== arr2.length) return false
for (var i = 0; i < length; i++)
if (arr1[i] !== arr2[i])
return false
return true
}
src dosyasının yolunun doğru olduğunu ve tüm js dosyalarının yüklendiğini doğrulayabilirim.