1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2
"http://www.w3.org/TR/html4/loose.dtd">
5
Copyright 2004 ThoughtWorks, Inc
7
Licensed under the Apache License, Version 2.0 (the "License");
8
you may not use this file except in compliance with the License.
9
You may obtain a copy of the License at
11
http://www.apache.org/licenses/LICENSE-2.0
13
Unless required by applicable law or agreed to in writing, software
14
distributed under the License is distributed on an "AS IS" BASIS,
15
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
See the License for the specific language governing permissions and
17
limitations under the License.
21
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
22
<title>JsMock Tests</title>
23
<link rel="stylesheet" type="text/css" href="../../jsunit/css/jsUnitStyle.css">
24
<script language="JavaScript" type="text/javascript" src="../../jsunit/app/jsUnitCore.js"></script>
25
<script language="JavaScript" type="text/javascript" src="mock.js"></script>
26
<script language="JavaScript" type="text/javascript">
28
function testCallingExpectedFunctionShouldPass() {
29
var myMock = new Mock()
30
myMock.expects("aslak")
35
function testAccessingExpectedPropertyShouldPass() {
36
var myMock = new Mock()
37
myMock.expectsProperty("hello").returns("world")
38
assertEquals("world", myMock.hello)
41
function testAccessingExpectedPropertyWithObjectShouldPass() {
42
var myMock = new Mock()
44
myMock.expectsProperty("hello").returns(ob)
45
assertEquals(ob, myMock.hello)
48
function testCallingUnexpectedFunctionShouldFail() {
49
var myMock = new Mock();
52
fail("Should fail because someMethod wasn't expected!");
58
function testNotCallingExpectedFunctionShouldFail() {
59
var myMock = new Mock()
60
myMock.expects("someMethod")
63
fail("Should fail because someMethod wasn't called!")
69
function testCallingTooManyExpectedFunctionShouldFail() {
70
var myMock = new Mock()
71
myMock.expects("someMethod")
76
fail("Should fail because someMethod was called more than once!")
82
function testCallingExpectedFunctionWithBadArgumentsShouldFail() {
83
var myMock = new Mock()
84
myMock.expects("someMethod", "foo")
86
myMock.someMethod("bar")
90
fail("Should fail because bar wasn't the expected arg!")
93
function testCallingExpectedFunctionWithExpectedArgumentsShouldPass() {
94
var myMock = new Mock()
95
myMock.expects("someMethod", "foo")
96
myMock.expects("anotherMethod", "bar", "zap")
97
assertUndefined(myMock.someMethod("foo"))
98
assertUndefined(myMock.anotherMethod("bar", "zap"))
101
function testCallingExpectedFunctionWithTooFewArgumentsShouldFail() {
102
var myMock = new Mock()
103
myMock.expects("someMethod", "foo", "bar")
105
myMock.someMethod("foo")
109
fail("Should fail because too few arguments were passed!")
112
function testCallingExpectedFunctionWithTooManyArgumentsShouldFail() {
113
var myMock = new Mock()
114
myMock.expects("someMethod", "foo")
116
myMock.someMethod("foo", "bar")
120
fail("Should fail because too many arguments were passed!")
123
function testShouldCreateMockInstancesWithoutSideffects() {
135
fail("Should fail because an unexpected bar was called!")
138
function testCallingExpectedFunctionWithReturnShouldReturnValue() {
139
var myMock = new Mock()
140
myMock.expects("someMethod", "bar").returns("foo")
141
myMock.expects("theOtherMethod", "zap", "ping", "pong").returns("bang")
142
assertEquals("foo", myMock.someMethod("bar"))
143
assertEquals("bang", myMock.theOtherMethod("zap", "ping", "pong"))
147
function testCallingExpectedFunctionWithThrowsShouldThrowError() {
148
var myMock = new Mock();
149
myMock.expects("someMethod", "bar").andThrows("failure")
151
myMock.someMethod("bar")
153
assertEquals("failure", e.message);
156
fail("Mock did not throw exception when required");
159
function testSettingExpectedPropertyShouldPass() {
160
var myMock = new Mock()
161
myMock.expectsProperty("foo", "bar")
166
function testShouldAllowExpectationOfSameFunctionWithDifferentArguments() {
167
var myMock = new Mock()
168
myMock.expects("aslak", "hello").returns("world")
169
myMock.expects("aslak", "bonjour").returns("monde")
170
assertEquals("world", myMock.aslak("hello"))
171
assertEquals("monde", myMock.aslak("bonjour"))
175
function TODO_testSettingUnexpectedPropertyShouldFail() {
176
var myMock = new Mock()
184
fail("Should fail because an unexpected property was set!")
187
function TODO_testNotSettingExpectedPropertyShouldFail() {
188
var myMock = new Mock()
189
myMock.expectsProperty("foo", "bar")
195
fail("Should fail because an expected property was not set!")
198
function TODO_testSettingExpectedPropertyWithUnexpectedValueShouldFail() {
199
var myMock = new Mock()
200
myMock.expectsProperty("foo", "bar")
207
fail("Should fail because an expected property was set with unexpected value!")
214
<h1>JsMock Tests</h1>
216
<p>This page contains tests for JsMock. To see them, take a look at the source. To run them, load this file via JsUnit's
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2
"http://www.w3.org/TR/html4/loose.dtd">
5
Copyright 2004 ThoughtWorks, Inc
7
Licensed under the Apache License, Version 2.0 (the "License");
8
you may not use this file except in compliance with the License.
9
You may obtain a copy of the License at
11
http://www.apache.org/licenses/LICENSE-2.0
13
Unless required by applicable law or agreed to in writing, software
14
distributed under the License is distributed on an "AS IS" BASIS,
15
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
See the License for the specific language governing permissions and
17
limitations under the License.
21
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
22
<title>JsMock Tests</title>
23
<link rel="stylesheet" type="text/css" href="../../jsunit/css/jsUnitStyle.css">
24
<script language="JavaScript" type="text/javascript" src="../../jsunit/app/jsUnitCore.js"></script>
25
<script language="JavaScript" type="text/javascript" src="mock.js"></script>
26
<script language="JavaScript" type="text/javascript">
28
function testCallingExpectedFunctionShouldPass() {
29
var myMock = new Mock()
30
myMock.expects("aslak")
35
function testAccessingExpectedPropertyShouldPass() {
36
var myMock = new Mock()
37
myMock.expectsProperty("hello").returns("world")
38
assertEquals("world", myMock.hello)
41
function testAccessingExpectedPropertyWithObjectShouldPass() {
42
var myMock = new Mock()
44
myMock.expectsProperty("hello").returns(ob)
45
assertEquals(ob, myMock.hello)
48
function testCallingUnexpectedFunctionShouldFail() {
49
var myMock = new Mock();
52
fail("Should fail because someMethod wasn't expected!");
58
function testNotCallingExpectedFunctionShouldFail() {
59
var myMock = new Mock()
60
myMock.expects("someMethod")
63
fail("Should fail because someMethod wasn't called!")
69
function testCallingTooManyExpectedFunctionShouldFail() {
70
var myMock = new Mock()
71
myMock.expects("someMethod")
76
fail("Should fail because someMethod was called more than once!")
82
function testCallingExpectedFunctionWithBadArgumentsShouldFail() {
83
var myMock = new Mock()
84
myMock.expects("someMethod", "foo")
86
myMock.someMethod("bar")
90
fail("Should fail because bar wasn't the expected arg!")
93
function testCallingExpectedFunctionWithExpectedArgumentsShouldPass() {
94
var myMock = new Mock()
95
myMock.expects("someMethod", "foo")
96
myMock.expects("anotherMethod", "bar", "zap")
97
assertUndefined(myMock.someMethod("foo"))
98
assertUndefined(myMock.anotherMethod("bar", "zap"))
101
function testCallingExpectedFunctionWithTooFewArgumentsShouldFail() {
102
var myMock = new Mock()
103
myMock.expects("someMethod", "foo", "bar")
105
myMock.someMethod("foo")
109
fail("Should fail because too few arguments were passed!")
112
function testCallingExpectedFunctionWithTooManyArgumentsShouldFail() {
113
var myMock = new Mock()
114
myMock.expects("someMethod", "foo")
116
myMock.someMethod("foo", "bar")
120
fail("Should fail because too many arguments were passed!")
123
function testShouldCreateMockInstancesWithoutSideffects() {
135
fail("Should fail because an unexpected bar was called!")
138
function testCallingExpectedFunctionWithReturnShouldReturnValue() {
139
var myMock = new Mock()
140
myMock.expects("someMethod", "bar").returns("foo")
141
myMock.expects("theOtherMethod", "zap", "ping", "pong").returns("bang")
142
assertEquals("foo", myMock.someMethod("bar"))
143
assertEquals("bang", myMock.theOtherMethod("zap", "ping", "pong"))
147
function testCallingExpectedFunctionWithThrowsShouldThrowError() {
148
var myMock = new Mock();
149
myMock.expects("someMethod", "bar").andThrows("failure")
151
myMock.someMethod("bar")
153
assertEquals("failure", e.message);
156
fail("Mock did not throw exception when required");
159
function testSettingExpectedPropertyShouldPass() {
160
var myMock = new Mock()
161
myMock.expectsProperty("foo", "bar")
166
function testShouldAllowExpectationOfSameFunctionWithDifferentArguments() {
167
var myMock = new Mock()
168
myMock.expects("aslak", "hello").returns("world")
169
myMock.expects("aslak", "bonjour").returns("monde")
170
assertEquals("world", myMock.aslak("hello"))
171
assertEquals("monde", myMock.aslak("bonjour"))
175
function TODO_testSettingUnexpectedPropertyShouldFail() {
176
var myMock = new Mock()
184
fail("Should fail because an unexpected property was set!")
187
function TODO_testNotSettingExpectedPropertyShouldFail() {
188
var myMock = new Mock()
189
myMock.expectsProperty("foo", "bar")
195
fail("Should fail because an expected property was not set!")
198
function TODO_testSettingExpectedPropertyWithUnexpectedValueShouldFail() {
199
var myMock = new Mock()
200
myMock.expectsProperty("foo", "bar")
207
fail("Should fail because an expected property was set with unexpected value!")
214
<h1>JsMock Tests</h1>
216
<p>This page contains tests for JsMock. To see them, take a look at the source. To run them, load this file via JsUnit's