Merge branch 'master' of git@github.com:pivotal/jasmine

This commit is contained in:
Christian Williams
2009-11-09 17:42:21 -05:00
48 changed files with 4841 additions and 984 deletions
+11 -7
View File
@@ -6,10 +6,10 @@ class JasmineHelper
def self.jasmine
['/lib/' + File.basename(Dir.glob("#{JasmineHelper.jasmine_lib_dir}/jasmine*.js").first)] +
['/lib/json2.js',
'/lib/TrivialReporter.js']
'/lib/TrivialReporter.js']
end
def self.jasmine_root
def self.jasmine_root
File.expand_path(File.join(File.dirname(__FILE__), '..'))
end
@@ -18,6 +18,10 @@ def self.jasmine_root
File.expand_path(File.join(jasmine_root, 'src'))
end
def self.jasmine_lib_dir
File.expand_path(File.join(jasmine_root, 'lib'))
end
def self.jasmine_spec_dir
File.expand_path(File.join(jasmine_root, 'spec'))
end
@@ -26,15 +30,15 @@ def self.jasmine_root
Dir.glob(File.join(jasmine_spec_dir, "**/*[Ss]pec.js"))
end
def self.spec_file_urls
raw_spec_files.collect {|f| f.sub(jasmine_spec_dir, "/spec")}
def self.specs
Jasmine.cachebust(raw_spec_files).collect {|f| f.sub(jasmine_spec_dir, "/spec")}
end
def self.dir_mappings
{
"/src" => jasmine_src_dir,
"/spec" => jasmine_spec_dir,
"/lib" => jasmine_lib_dir
"/src" => jasmine_src_dir,
"/spec" => jasmine_spec_dir,
"/lib" => jasmine_lib_dir
}
end
end
+1 -1
View File
@@ -4,7 +4,7 @@ require File.expand_path(File.join(File.dirname(__FILE__), "jasmine_helper.rb"))
require File.expand_path(File.join(JasmineHelper.jasmine_root, "contrib/ruby/jasmine_spec_builder"))
jasmine_runner = Jasmine::Runner.new(SeleniumRC::Server.new.jar_path,
JasmineHelper.spec_file_urls,
JasmineHelper.specs,
JasmineHelper.dir_mappings)
spec_builder = Jasmine::SpecBuilder.new(JasmineHelper.raw_spec_files, jasmine_runner)
+1
View File
@@ -25,6 +25,7 @@
<script type="text/javascript" src="../src/WaitsForBlock.js"></script>
<script type="text/javascript" src="../lib/TrivialReporter.js"></script>
<script type="text/javascript" src="../lib/consolex.js"></script>
<script type="text/javascript">
+3 -3
View File
@@ -6,7 +6,7 @@ describe('Exceptions:', function() {
env.updateInterval = 0;
});
it('jasmine.formatException formats Firefox exception maessages as expected', function() {
it('jasmine.formatException formats Firefox exception messages as expected', function() {
var sampleFirefoxException = {
fileName: 'foo.js',
line: '1978',
@@ -19,7 +19,7 @@ describe('Exceptions:', function() {
expect(jasmine.util.formatException(sampleFirefoxException)).toEqual(expected);
});
it('jasmine.formatException formats Webkit exception maessages as expected', function() {
it('jasmine.formatException formats Webkit exception messages as expected', function() {
var sampleWebkitException = {
sourceURL: 'foo.js',
lineNumber: '1978',
@@ -81,7 +81,7 @@ describe('Exceptions:', function() {
var specResults = suiteResults.getItems();
expect(suiteResults.passed()).toEqual(false);
//
expect(specResults.length).toEqual(5);
expect(specResults[0].passed()).toMatch(false);
var blockResults = specResults[0].getItems();
+411 -131
View File
@@ -1,20 +1,14 @@
describe("jasmine.Matchers", function() {
var env;
var env, mockSpec;
beforeEach(function() {
env = new jasmine.Env();
env.updateInterval = 0;
mockSpec = jasmine.createSpyObj('spec', ['addMatcherResult']);
});
function match(value) {
return new jasmine.Matchers(env, value);
}
function detailsFor(actual, matcherName, matcherArgs) {
var matcher = match(actual);
matcher[matcherName].apply(matcher, matcherArgs);
expect(matcher.results().getItems().length).toEqual(1);
return matcher.results().getItems()[0].details;
function match(value) {
return new jasmine.Matchers(env, value, mockSpec);
}
it("toEqual with primitives, objects, dates, html nodes, etc.", function() {
@@ -22,8 +16,12 @@ describe("jasmine.Matchers", function() {
expect(match({foo:'bar'}).toEqual(null)).toEqual(false);
var functionA = function() { return 'hi'; };
var functionB = function() { return 'hi'; };
var functionA = function() {
return 'hi';
};
var functionB = function() {
return 'hi';
};
expect(match({foo:functionA}).toEqual({foo:functionB})).toEqual(false);
expect(match({foo:functionA}).toEqual({foo:functionA})).toEqual(true);
@@ -49,6 +47,37 @@ describe("jasmine.Matchers", function() {
expect((match(['a', 'b']).toEqual(['a', 'b', undefined]))).toEqual(false);
});
it("toEqual to build an Expectation Result", function() {
var actual = 'a';
var matcher = match(actual);
var expected = 'b';
matcher.toEqual(expected);
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
expect(result.matcherName).toEqual("toEqual");
expect(result.passed()).toEqual(false);
expect(result.message).toMatch(jasmine.pp(actual));
expect(result.message).toMatch(jasmine.pp(expected));
expect(result.expected).toEqual(expected);
expect(result.actual).toEqual(actual);
});
it("toNotEqual to build an Expectation Result", function() {
var str = 'a';
var matcher = match(str);
matcher.toNotEqual(str);
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
expect(result.matcherName).toEqual("toNotEqual");
expect(result.passed()).toEqual(false);
expect(result.message).toMatch(jasmine.pp(str));
expect(result.message).toMatch('not');
expect(result.expected).toEqual(str);
expect(result.actual).toEqual(str);
});
it('toBe should return true only if the expected and actual items === each other', function() {
var a = {};
var b = {};
@@ -62,6 +91,35 @@ describe("jasmine.Matchers", function() {
expect((match(a).toNotBe(c))).toEqual(false);
});
it("toBe to build an ExpectationResult", function() {
var expected = 'b';
var actual = 'a';
var matcher = match(actual);
matcher.toBe(expected);
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
expect(result.matcherName).toEqual("toBe");
expect(result.passed()).toEqual(false);
expect(result.message).toMatch(jasmine.pp(actual));
expect(result.message).toMatch(jasmine.pp(expected));
expect(result.expected).toEqual(expected);
expect(result.actual).toEqual(actual);
});
it("toNotBe to build an ExpectationResult", function() {
var str = 'a';
var matcher = match(str);
matcher.toNotBe(str);
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
expect(result.matcherName).toEqual("toNotBe");
expect(result.passed()).toEqual(false);
expect(result.message).toMatch(str);
expect(result.expected).toEqual(str);
expect(result.actual).toEqual(str);
});
it("toMatch and #toNotMatch should perform regular expression matching on strings", function() {
expect((match('foobarbel').toMatch(/bar/))).toEqual(true);
@@ -77,17 +135,127 @@ describe("jasmine.Matchers", function() {
expect((match('foobazbel').toNotMatch("bar"))).toEqual(true);
});
it("toMatch w/ RegExp to build an ExpectationResult", function() {
var actual = 'a';
var matcher = match(actual);
var expected = /b/;
matcher.toMatch(expected);
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
expect(result.matcherName).toEqual("toMatch");
expect(result.passed()).toEqual(false);
expect(result.message).toMatch(jasmine.pp(actual));
expect(result.message).toMatch(expected.toString());
expect(result.expected).toEqual(expected);
expect(result.actual).toEqual(actual);
});
it("toMatch w/ String to build an ExpectationResult", function() {
var actual = 'a';
var matcher = match(actual);
var expected = 'b';
matcher.toMatch(expected);
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
expect(result.matcherName).toEqual("toMatch");
expect(result.passed()).toEqual(false);
expect(result.message).toMatch(jasmine.pp(actual));
expect(result.message).toMatch(new RegExp(expected).toString());
expect(result.expected).toEqual(expected);
expect(result.actual).toEqual(actual);
});
it("toNotMatch w/ RegExp to build an ExpectationResult", function() {
var actual = 'a';
var matcher = match(actual);
var expected = /a/;
matcher.toNotMatch(expected);
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
expect(result.matcherName).toEqual("toNotMatch");
expect(result.passed()).toEqual(false);
expect(result.message).toMatch(expected.toString());
expect(result.message).toMatch(jasmine.pp(actual));
expect(result.message).toMatch("not");
expect(result.expected).toEqual(expected);
expect(result.actual).toEqual(actual);
});
it("toNotMatch w/ String to build an ExpectationResult", function() {
var str = 'a';
var matcher = match(str);
matcher.toNotMatch(str);
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
expect(result.matcherName).toEqual("toNotMatch");
expect(result.passed()).toEqual(false);
expect(result.message).toMatch(jasmine.pp(str));
expect(result.message).toMatch(new RegExp(str).toString());
expect(result.message).toMatch("not");
expect(result.expected).toEqual(str);
expect(result.actual).toEqual(str);
});
it("toBeDefined", function() {
expect(match('foo').toBeDefined()).toEqual(true);
expect(match(undefined).toBeDefined()).toEqual(false);
});
it("toBeDefined to build an ExpectationResult", function() {
var matcher = match(undefined);
matcher.toBeDefined();
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
expect(result.matcherName).toEqual("toBeDefined");
expect(result.passed()).toEqual(false);
expect(result.message).toEqual('Expected actual to not be undefined.');
expect(result.actual).toEqual(undefined);
});
it("toBeUndefined", function() {
expect(match('foo').toBeUndefined()).toEqual(false);
expect(match(undefined).toBeUndefined()).toEqual(true);
});
it("toBeNull", function() {
expect(match(null).toBeNull()).toEqual(true);
expect(match(undefined).toBeNull()).toEqual(false);
expect(match("foo").toBeNull()).toEqual(false);
});
it("toBeNull w/ String to build an ExpectationResult", function() {
var actual = 'a';
var matcher = match(actual);
matcher.toBeNull();
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
expect(result.matcherName).toEqual("toBeNull");
expect(result.passed()).toEqual(false);
expect(result.message).toMatch(jasmine.pp(actual));
expect(result.message).toMatch('null');
expect(result.actual).toEqual(actual);
});
it("toBeNull w/ Object to build an ExpectationResult", function() {
var actual = {a: 'b'};
var matcher = match(actual);
matcher.toBeNull();
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
expect(result.matcherName).toEqual("toBeNull");
expect(result.passed()).toEqual(false);
expect(result.message).toMatch(jasmine.pp(actual));
expect(result.message).toMatch('null');
expect(result.actual).toEqual(actual);
});
it("toBeFalsy", function() {
expect(match(false).toBeFalsy()).toEqual(true);
expect(match(true).toBeFalsy()).toEqual(false);
@@ -96,6 +264,20 @@ describe("jasmine.Matchers", function() {
expect(match("").toBeFalsy()).toEqual(true);
});
it("toBeFalsy to build an ExpectationResult", function() {
var actual = 'a';
var matcher = match(actual);
matcher.toBeFalsy();
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
expect(result.matcherName).toEqual("toBeFalsy");
expect(result.passed()).toEqual(false);
expect(result.message).toMatch(jasmine.pp(actual));
expect(result.message).toMatch('falsy');
expect(result.actual).toEqual(actual);
});
it("toBeTruthy", function() {
expect(match(false).toBeTruthy()).toEqual(false);
expect(match(true).toBeTruthy()).toEqual(true);
@@ -107,6 +289,18 @@ describe("jasmine.Matchers", function() {
expect(match({foo: 1}).toBeTruthy()).toEqual(true);
});
it("toBeTruthy to build an ExpectationResult", function() {
var matcher = match(false);
matcher.toBeTruthy();
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
expect(result.matcherName).toEqual("toBeTruthy");
expect(result.passed()).toEqual(false);
expect(result.message).toEqual("Expected actual to be truthy");
expect(result.actual).toEqual(false);
});
it("toEqual", function() {
expect(match(undefined).toEqual(undefined)).toEqual(true);
expect(match({foo:'bar'}).toEqual({foo:'bar'})).toEqual(true);
@@ -122,10 +316,13 @@ describe("jasmine.Matchers", function() {
expect(match("foo").toEqual(jasmine.any(Object))).toEqual(false);
expect(match({someObj:'foo'}).toEqual(jasmine.any(Object))).toEqual(true);
expect(match({someObj:'foo'}).toEqual(jasmine.any(Function))).toEqual(false);
expect(match(function() {}).toEqual(jasmine.any(Object))).toEqual(false);
expect(match(function() {
}).toEqual(jasmine.any(Object))).toEqual(false);
expect(match(["foo", "goo"]).toEqual(["foo", jasmine.any(String)])).toEqual(true);
expect(match(function() {}).toEqual(jasmine.any(Function))).toEqual(true);
expect(match(["a", function() {}]).toEqual(["a", jasmine.any(Function)])).toEqual(true);
expect(match(function() {
}).toEqual(jasmine.any(Function))).toEqual(true);
expect(match(["a", function() {
}]).toEqual(["a", jasmine.any(Function)])).toEqual(true);
});
it("toEqual handles circular objects ok", function() {
@@ -154,7 +351,7 @@ describe("jasmine.Matchers", function() {
it("toContain and toNotContain", function() {
expect(match('ABC').toContain('A')).toEqual(true);
expect(match('ABC').toContain('X')).toEqual(false);
expect(match(['A', 'B', 'C']).toContain('A')).toEqual(true);
expect(match(['A', 'B', 'C']).toContain('F')).toEqual(false);
expect(match(['A', 'B', 'C']).toNotContain('F')).toEqual(true);
@@ -162,10 +359,40 @@ describe("jasmine.Matchers", function() {
expect(match(['A', {some:'object'}, 'C']).toContain({some:'object'})).toEqual(true);
expect(match(['A', {some:'object'}, 'C']).toContain({some:'other object'})).toEqual(false);
});
expect(detailsFor('abc', 'toContain', ['x'])).toEqual({
matcherName: 'toContain', expected: 'x', actual: 'abc'
});
it("toContain to build an ExpectationResult", function() {
var actual = ['a','b','c'];
var matcher = match(actual);
var expected = 'x';
matcher.toContain(expected);
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
expect(result.matcherName).toEqual("toContain");
expect(result.passed()).toEqual(false);
expect(result.message).toMatch(jasmine.pp(actual));
expect(result.message).toMatch('contain');
expect(result.message).toMatch(jasmine.pp(expected));
expect(result.actual).toEqual(actual);
expect(result.expected).toEqual(expected);
});
it("toNotContain to build an ExpectationResult", function() {
var actual = ['a','b','c'];
var matcher = match(actual);
var expected = 'b';
matcher.toNotContain(expected);
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
expect(result.matcherName).toEqual("toNotContain");
expect(result.passed()).toEqual(false);
expect(result.message).toMatch(jasmine.pp(actual));
expect(result.message).toMatch('not contain');
expect(result.message).toMatch(jasmine.pp(expected));
expect(result.actual).toEqual(actual);
expect(result.expected).toEqual(expected);
});
it("toBeLessThan should pass if actual is less than expected", function() {
@@ -174,141 +401,194 @@ describe("jasmine.Matchers", function() {
expect(match(37).toBeLessThan(37)).toEqual(false);
});
it("toBeLessThan to build an ExpectationResult", function() {
var actual = 3;
var matcher = match(actual);
var expected = 1;
matcher.toBeLessThan(expected);
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
expect(result.matcherName).toEqual("toBeLessThan");
expect(result.passed()).toEqual(false);
expect(result.message).toMatch(jasmine.pp(actual) + ' to be less than');
expect(result.message).toMatch(jasmine.pp(expected));
expect(result.actual).toEqual(actual);
expect(result.expected).toEqual(expected);
});
it("toBeGreaterThan should pass if actual is greater than expected", function() {
expect(match(37).toBeGreaterThan(42)).toEqual(false);
expect(match(37).toBeGreaterThan(-42)).toEqual(true);
expect(match(37).toBeGreaterThan(37)).toEqual(false);
});
it("toBeGreaterThan to build an ExpectationResult", function() {
var actual = 1;
var matcher = match(actual);
var expected = 3;
matcher.toBeGreaterThan(expected);
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
expect(result.matcherName).toEqual("toBeGreaterThan");
expect(result.passed()).toEqual(false);
expect(result.message).toMatch(jasmine.pp(actual) + ' to be greater than');
expect(result.message).toMatch(jasmine.pp(expected));
expect(result.actual).toEqual(actual);
expect(result.expected).toEqual(expected);
});
it("toThrow", function() {
var expected = new jasmine.Matchers(env, function() {
throw new Error("Fake Error");
});
}, mockSpec);
expect(expected.toThrow()).toEqual(true);
expect(expected.toThrow("Fake Error")).toEqual(true);
expect(expected.toThrow(new Error("Fake Error"))).toEqual(true);
expect(expected.toThrow("Other Error")).toEqual(false);
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
expect(result.message).toMatch("Other Error");
expect(expected.toThrow(new Error("Other Error"))).toEqual(false);
result = mockSpec.addMatcherResult.mostRecentCall.args[0];
expect(result.message).toMatch("Other Error");
var exception;
try {
(function () {
new jasmine.Matchers(env, 'not-a-function', mockSpec).toThrow();
})();
} catch (e) {
exception = e;
}
;
expect(exception).toBeDefined();
expect(exception.message).toEqual('Actual is not a function');
expect(match(function() {
}).toThrow()).toEqual(false);
result = mockSpec.addMatcherResult.mostRecentCall.args[0];
expect(result.message).toEqual('Expected function to throw an exception.');
expect(match(function() {}).toThrow()).toEqual(false);
});
it("wasCalled, wasNotCalled, wasCalledWith", function() {
var currentSuite;
var spec;
currentSuite = env.describe('default current suite', function() {
spec = env.it();
describe("wasCalled, wasNotCalled, wasCalledWith", function() {
var TestClass;
beforeEach(function() {
TestClass = { someFunction: function() {
} };
});
describe('without spies', function() {
it('should always show an error', function () {
expect(match(TestClass.someFunction).wasCalled()).toEqual(false);
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
expect(result.message).toEqual("Actual is not a spy.");
expect(match(TestClass.someFunction).wasNotCalled()).toEqual(false);
result = mockSpec.addMatcherResult.mostRecentCall.args[0];
expect(result.message).toEqual("Actual is not a spy.");
});
});
var TestClass = { someFunction: function() {
} };
describe('with spies', function () {
var expected;
expect(match(TestClass.someFunction).wasCalled()).toEqual(false);
expect(match(TestClass.someFunction).wasNotCalled()).toEqual(false);
beforeEach(function () {
TestClass.someFunction = jasmine.createSpy("My spy");
});
spec.spyOn(TestClass, 'someFunction');
it("should track if it was called", function() {
expect(match(TestClass.someFunction).wasCalled()).toEqual(false);
expect(match(TestClass.someFunction).wasNotCalled()).toEqual(true);
expect(match(TestClass.someFunction).wasCalled()).toEqual(false);
expect(match(TestClass.someFunction).wasNotCalled()).toEqual(true);
TestClass.someFunction();
expect(match(TestClass.someFunction).wasCalled()).toEqual(true);
expect(function () {
match(TestClass.someFunction).wasCalled('some arg');
}).toThrow('wasCalled does not take arguments, use wasCalledWith');
expect(match(TestClass.someFunction).wasNotCalled()).toEqual(false);
});
it('should return true if it was called with the expected args', function() {
TestClass.someFunction('a', 'b', 'c');
expect(match(TestClass.someFunction).wasCalledWith('a', 'b', 'c')).toEqual(true);
});
it('should return false if it was not called with the expected args', function() {
TestClass.someFunction('a', 'b', 'c');
var expected = match(TestClass.someFunction);
expect(expected.wasCalledWith('c', 'b', 'a')).toEqual(false);
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
expect(result.passed()).toEqual(false);
expect(result.expected).toEqual(['c', 'b', 'a']);
expect(result.actual.mostRecentCall.args).toEqual(['a', 'b', 'c']);
});
it('should allow matches across multiple calls', function() {
var expected = match(TestClass.someFunction);
TestClass.someFunction('a', 'b', 'c');
TestClass.someFunction('d', 'e', 'f');
expect(expected.wasCalledWith('a', 'b', 'c')).toEqual(true);
expect(expected.wasCalledWith('d', 'e', 'f')).toEqual(true);
expect(expected.wasCalledWith('x', 'y', 'z')).toEqual(false);
});
});
});
TestClass.someFunction();
expect(match(TestClass.someFunction).wasCalled()).toEqual(true);
expect(match(TestClass.someFunction).wasCalled('some arg')).toEqual(false);
expect(match(TestClass.someFunction).wasNotCalled()).toEqual(false);
TestClass.someFunction('a', 'b', 'c');
expect(match(TestClass.someFunction).wasCalledWith('a', 'b', 'c')).toEqual(true);
expected = match(TestClass.someFunction);
expect(expected.wasCalledWith('c', 'b', 'a')).toEqual(false);
expect(expected.results().getItems()[0].passed()).toEqual(false);
TestClass.someFunction.reset();
TestClass.someFunction('a', 'b', 'c');
TestClass.someFunction('d', 'e', 'f');
expect(expected.wasCalledWith('a', 'b', 'c')).toEqual(true);
expect(expected.wasCalledWith('d', 'e', 'f')).toEqual(true);
expect(expected.wasCalledWith('x', 'y', 'z')).toEqual(false);
expect(detailsFor(TestClass.someFunction, 'wasCalledWith', ['x', 'y', 'z'])).toEqual({
matcherName: 'wasCalledWith', expected: ['x', 'y', 'z'], actual: TestClass.someFunction.argsForCall
describe("wasCalledWith to build an ExpectationResult", function () {
var TestClass;
beforeEach(function() {
var currentSuite;
var spec;
currentSuite = env.describe('default current suite', function() {
spec = env.it();
}, spec);
TestClass = { someFunction: function(a, b) {
} };
spec.spyOn(TestClass, 'someFunction');
});
it("should handle case of actual not being a spy", function() {
var matcher = match();
matcher.wasCalledWith('a', 'b');
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
expect(result.matcherName).toEqual("wasCalledWith");
expect(result.passed()).toEqual(false);
expect(result.message).toEqual("Actual is not a spy");
expect(result.actual).toEqual(undefined);
expect(result.expected).toEqual(['a','b']);
matcher = match('foo');
matcher.wasCalledWith('a', 'b');
result = mockSpec.addMatcherResult.mostRecentCall.args[0];
expect(result.matcherName).toEqual("wasCalledWith");
expect(result.passed()).toEqual(false);
expect(result.message).toEqual("Actual is not a spy");
expect(result.actual).toEqual('foo');
expect(result.expected).toEqual(['a','b']);
});
it("should should handle the case of a spy", function() {
TestClass.someFunction('a', 'c');
var matcher = match(TestClass.someFunction);
matcher.wasCalledWith('a', 'b');
var result = mockSpec.addMatcherResult.mostRecentCall.args[0];
expect(result.matcherName).toEqual("wasCalledWith");
expect(result.passed()).toEqual(false);
expect(result.message).toMatch("['a', 'b']");
expect(result.message).toMatch("['a', 'c']");
expect(result.actual).toEqual(TestClass.someFunction);
expect(result.expected).toEqual(['a','b']);
});
});
it("should report mismatches in some nice way", function() {
var results = new jasmine.NestedResults();
var expected = new jasmine.Matchers(env, true, results);
expected.toEqual(true);
expected.toEqual(false);
expect(results.getItems().length).toEqual(2);
expect(results.getItems()[0].passed()).toEqual(true);
expect(results.getItems()[1].passed()).toEqual(false);
results = new jasmine.NestedResults();
expected = new jasmine.Matchers(env, false, results);
expected.toEqual(true);
var expectedMessage = 'Expected<br /><br />true<br /><br />but got<br /><br />false<br />';
expect(results.getItems()[0].message).toEqual(expectedMessage);
results = new jasmine.NestedResults();
expected = new jasmine.Matchers(env, null, results);
expected.toEqual('not null');
expectedMessage = 'Expected<br /><br />\'not null\'<br /><br />but got<br /><br />null<br />';
expect(results.getItems()[0].message).toEqual(expectedMessage);
results = new jasmine.NestedResults();
expected = new jasmine.Matchers(env, undefined, results);
expected.toEqual('not undefined');
expectedMessage = 'Expected<br /><br />\'not undefined\'<br /><br />but got<br /><br />undefined<br />';
expect(results.getItems()[0].message).toEqual(expectedMessage);
results = new jasmine.NestedResults();
expected = new jasmine.Matchers(env, {foo:'one',baz:'two', more: 'blah'}, results);
expected.toEqual({foo:'one', bar: '<b>three</b> &', baz: '2'});
expectedMessage =
"Expected<br /><br />{ foo : 'one', bar : '&lt;b&gt;three&lt;/b&gt; &amp;', baz : '2' }<br /><br />but got<br /><br />{ foo : 'one', baz : 'two', more : 'blah' }<br />" +
"<br /><br />Different Keys:<br />" +
"expected has key 'bar', but missing from <b>actual</b>.<br />" +
"<b>expected</b> missing key 'more', but present in actual.<br />" +
"<br /><br />Different Values:<br />" +
"'bar' was<br /><br />'&lt;b&gt;three&lt;/b&gt; &amp;'<br /><br />in expected, but was<br /><br />'undefined'<br /><br />in actual.<br /><br />" +
"'baz' was<br /><br />'2'<br /><br />in expected, but was<br /><br />'two'<br /><br />in actual.<br /><br />";
var actualMessage = results.getItems()[0].message;
expect(actualMessage).toEqual(expectedMessage);
results = new jasmine.NestedResults();
expected = new jasmine.Matchers(env, true, results);
expected.toEqual(true);
expect(results.getItems()[0].message).toEqual('Passed.');
expected = new jasmine.Matchers(env, [1, 2, 3], results);
results.getItems().length = 0;
expected.toEqual([1, 2, 3]);
expect(results.getItems()[0].passed()).toEqual(true);
expected = new jasmine.Matchers(env, [1, 2, 3], results);
results.getItems().length = 0;
expected.toEqual([{}, {}, {}]);
expect(results.getItems()[0].passed()).toEqual(false);
expected = new jasmine.Matchers(env, [{}, {}, {}], results);
results.getItems().length = 0;
expected.toEqual([1, 2, 3]);
expect(results.getItems()[0].passed()).toEqual(false);
});
});
})
;
+34
View File
@@ -0,0 +1,34 @@
describe("MockClock", function () {
beforeEach(function() {
jasmine.Clock.useMock();
});
describe("setTimeout", function () {
it("should mock the clock when useMock is in a beforeEach", function() {
var expected = false;
setTimeout(function() {
expected = true;
}, 30000);
expect(expected).toBe(false);
jasmine.Clock.tick(30001);
expect(expected).toBe(true);
});
});
describe("setInterval", function () {
it("should mock the clock when useMock is in a beforeEach", function() {
var interval = 0;
setInterval(function() {
interval++;
}, 30000);
expect(interval).toEqual(0);
jasmine.Clock.tick(30001);
expect(interval).toEqual(1);
jasmine.Clock.tick(30001);
expect(interval).toEqual(2);
jasmine.Clock.tick(1);
expect(interval).toEqual(2);
});
});
});
+20 -7
View File
@@ -3,14 +3,18 @@ describe('jasmine.NestedResults', function() {
// Leaf case
var results = new jasmine.NestedResults();
results.addResult(new jasmine.ExpectationResult(true,'Passed.'));
results.addResult(new jasmine.ExpectationResult({
matcherName: "foo", passed: true, message: 'Passed.', actual: 'bar', expected: 'bar'}
));
expect(results.getItems().length).toEqual(1);
expect(results.totalCount).toEqual(1);
expect(results.passedCount).toEqual(1);
expect(results.failedCount).toEqual(0);
results.addResult(new jasmine.ExpectationResult(false, 'FAIL.'));
results.addResult(new jasmine.ExpectationResult({
matcherName: "baz", passed: false, message: 'FAIL.', actual: "corge", expected: "quux"
}));
expect(results.getItems().length).toEqual(2);
expect(results.totalCount).toEqual(2);
@@ -21,12 +25,21 @@ describe('jasmine.NestedResults', function() {
it('should roll up counts for nested results', function() {
// Branch case
var leafResultsOne = new jasmine.NestedResults();
leafResultsOne.addResult(new jasmine.ExpectationResult( true, ''));
leafResultsOne.addResult(new jasmine.ExpectationResult( false, ''));
leafResultsOne.addResult(new jasmine.ExpectationResult({
matcherName: "toSomething", passed: true, message: 'message', actual: '', expected:''
}));
leafResultsOne.addResult(new jasmine.ExpectationResult({
matcherName: "toSomethingElse", passed: false, message: 'message', actual: 'a', expected: 'b'
}));
var leafResultsTwo = new jasmine.NestedResults();
leafResultsTwo.addResult(new jasmine.ExpectationResult( true, ''));
leafResultsTwo.addResult(new jasmine.ExpectationResult( false, ''));
leafResultsTwo.addResult(new jasmine.ExpectationResult({
matcherName: "toSomething", passed: true, message: 'message', actual: '', expected: ''
}));
leafResultsTwo.addResult(new jasmine.ExpectationResult({
matcherName: "toSomethineElse", passed: false, message: 'message', actual: 'c', expected: 'd'
}));
var branchResults = new jasmine.NestedResults();
branchResults.addResult(leafResultsOne);
@@ -38,4 +51,4 @@ describe('jasmine.NestedResults', function() {
expect(branchResults.failedCount).toEqual(2);
});
});
});
-1
View File
@@ -37,7 +37,6 @@ describe("jasmine spec running", function () {
expect(it4.id).toEqual(4);
});
it("should build up some objects with results we can inspect", function() {
var specWithNoBody, specWithExpectation, specWithFailingExpectations, specWithMultipleExpectations;
+97 -5
View File
@@ -8,19 +8,21 @@ describe("TrivialReporter", function() {
function fakeSpec(name) {
return {
getFullName: function() { return name; }
getFullName: function() {
return name;
}
};
}
it("should run only specs beginning with spec parameter", function() {
trivialReporter = new jasmine.TrivialReporter({ location: {search: "?spec=run%20this"} });
var trivialReporter = new jasmine.TrivialReporter({ location: {search: "?spec=run%20this"} });
expect(trivialReporter.specFilter(fakeSpec("run this"))).toBeTruthy();
expect(trivialReporter.specFilter(fakeSpec("not the right spec"))).toBeFalsy();
expect(trivialReporter.specFilter(fakeSpec("not run this"))).toBeFalsy();
});
it("should display empty divs for every suite when the runner is starting", function() {
trivialReporter = new jasmine.TrivialReporter({ body: body });
var trivialReporter = new jasmine.TrivialReporter({ body: body });
trivialReporter.reportRunnerStarting({
suites: function() {
return [ new jasmine.Suite({}, "suite 1", null, null) ];
@@ -31,5 +33,95 @@ describe("TrivialReporter", function() {
expect(divs.length).toEqual(2);
expect(divs[1].innerHTML).toContain("suite 1");
});
});
describe('Matcher reporting', function () {
var getResultMessageDiv = function (body) {
var divs = body.getElementsByTagName("div");
for (var i = 0; i < divs.length; i++) {
if (divs[i].className.match(/resultMessage/)) {
return divs[i];
}
}
};
var runner, spec, fakeTimer;
beforeEach(function () {
var env = new jasmine.Env();
fakeTimer = new jasmine.FakeTimer();
env.setTimeout = fakeTimer.setTimeout;
env.clearTimeout = fakeTimer.clearTimeout;
env.setInterval = fakeTimer.setInterval;
env.clearInterval = fakeTimer.clearInterval;
runner = env.currentRunner();
var suite = new jasmine.Suite(env, 'some suite');
runner.add(suite);
spec = new jasmine.Spec(env, suite, 'some spec');
suite.add(spec);
var trivialReporter = new jasmine.TrivialReporter({ body: body, location: {search: "?"} });
env.addReporter(trivialReporter);
});
describe('toContain', function () {
it('should show actual and expected', function () {
spec.runs(function () {
this.expect('foo').toContain('bar');
});
runner.execute();
fakeTimer.tick(0);
var resultEl = getResultMessageDiv(body);
expect(resultEl.innerHTML).toMatch(/foo/);
expect(resultEl.innerHTML).toMatch(/bar/);
});
});
});
describe("failure messages (integration)", function () {
var spec, results, expectationResult;
beforeEach(function() {
results = {
passed: function() {
return false;
},
getItems: function() {
}};
spec = {
suite: {
getFullName: function() {
return "suite 1";
}
},
getFullName: function() {
return "foo";
},
results: function() {
return results;
}
};
trivialReporter = new jasmine.TrivialReporter({ body: body });
trivialReporter.reportRunnerStarting({
suites: function() {
return [ new jasmine.Suite({}, "suite 1", null, null) ];
}
});
});
it("should add the failure message to the DOM (non-toEquals matchers)", function() {
expectationResult = new jasmine.ExpectationResult({
matcherName: "toBeNull", passed: false, message: "Expected 'a' to be null, but it was not"
});
spyOn(results, 'getItems').andReturn([expectationResult]);
trivialReporter.reportSpecResults(spec);
var divs = body.getElementsByTagName("div");
expect(divs[3].innerHTML).toEqual("Expected 'a' to be null, but it was not");
});
});
});
+23
View File
@@ -0,0 +1,23 @@
describe("jasmine.util", function() {
describe("extend", function () {
it("should add properies to a destination object ", function() {
var destination = {baz: 'baz'};
jasmine.util.extend(destination, {
foo: 'foo', bar: 'bar'
});
expect(destination).toEqual({foo: 'foo', bar: 'bar', baz: 'baz'});
});
it("should replace properies that already exist on a destination object", function() {
var destination = {foo: 'foo'};
jasmine.util.extend(destination, {
foo: 'bar'
});
expect(destination).toEqual({foo: 'bar'});
jasmine.util.extend(destination, {
foo: null
});
expect(destination).toEqual({foo: null});
});
});
});