Try out a Karma test or two

- #1993
This commit is contained in:
Doug Bunting 2015-02-23 11:15:19 -08:00
parent 8b1bd343ba
commit d696f268f7
5 changed files with 145 additions and 1 deletions

View File

@ -6,5 +6,6 @@
"devDependencies": {
"grunt": "^0.4.5",
"grunt-bower-task": "^0.4.0"
}
},
"private" : true
}

View File

@ -0,0 +1,70 @@
// Karma configuration
// Generated on Wed Feb 18 2015 20:46:05 GMT-0800 (Pacific Standard Time)
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [
'test/**/*.js'
],
// list of files to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// forward some requests to another server
proxies: {
"/MvcTagHelper_Home": "http://localhost:5000"
},
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['PhantomJS'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true
});
};

View File

@ -0,0 +1,13 @@
{
"version": "0.0.0",
"name": "MvcTagHelpersWebSite",
"description": "Web site demonstrating various MVC tag helpers.",
"devDependencies": {
"jasmine-core": "^2.2.0",
"karma": "^0.12.31",
"karma-jasmine": "^0.3.5",
"karma-phantomjs-launcher": "^0.1.4",
"karma-teamcity-reporter": "^0.1.2"
},
"private": true
}

View File

@ -0,0 +1,49 @@
describe("Basic function that doesn't use service", function() {
if (typeof NS == 'undefined') { NS = {}; }
NS.myFunction = {
// empty stuff array, filled during initialization
stuff: [],
init: function init() {
this.stuff.push('Testing');
},
reset: function reset() {
this.stuff = [];
},
append: function append(string1, string2) {
return string1 + ' ' + string2;
}
};
var myfunc = NS.myFunction;
beforeEach(function(){
spyOn(myfunc, 'init').and.callThrough();
});
afterEach(function() {
myfunc.reset();
});
it("should be able to initialize", function() {
expect(myfunc.init).toBeDefined();
myfunc.init();
expect(myfunc.init).toHaveBeenCalled();
});
it("should populate stuff during initialization", function(){
myfunc.init();
expect(myfunc.stuff.length).toEqual(1);
expect(myfunc.stuff[0]).toEqual('Testing');
});
describe("appending strings", function() {
it("should be able to append 2 strings", function() {
expect(myfunc.append).toBeDefined();
});
it("should append 2 strings", function() {
expect(myfunc.append('hello', 'world')).toEqual('hello world');
});
});
});

View File

@ -0,0 +1,11 @@
describe("<script/> tag helper", function () {
beforeEach(function() {
browser().navigateTo('/MvcTagHelper_Home/Script');
});
it("should not block page load", function() {
expect(browser().location().path()).toBe("/MvcTagHelper_Home/Script");
});
});