sku-pg
Version:
Skulpt is a Javascript implementation of Python 2.x. Python that runs in your browser!
103 lines (86 loc) • 3.1 kB
HTML
<html>
<!--
Copyright 2012 The Closure Library Authors. All Rights Reserved.
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
-->
<head>
<title>Closure Unit Tests - Object matchers</title>
<script src="../../base.js"></script>
<script>
goog.require('goog.labs.testing.ObjectEqualsMatcher');
goog.require('goog.labs.testing.HasPropertyMatcher');
goog.require('goog.labs.testing.InstanceOfMatcher');
goog.require('goog.labs.testing.IsNullOrUndefinedMatcher');
goog.require('goog.labs.testing.IsNullMatcher');
goog.require('goog.labs.testing.IsUndefinedMatcher');
goog.require('goog.labs.testing.assertThat');
goog.require('goog.testing.jsunit');
</script>
</head>
<body>
<script>
function testObjectEquals() {
var obj1 = {x: 1};
var obj2 = obj1;
goog.labs.testing.assertThat(obj1, equalsObject(obj2), 'obj1 equals obj2');
assertMatcherError(function() {
goog.labs.testing.assertThat({x: 1}, equalsObject({}));
}, 'equalsObject does not throw exception on failure');
}
function testInstanceOf() {
function expected() {
this.x = 1;
}
var input = new expected();
goog.labs.testing.assertThat(input, instanceOfClass(expected),
'input is an instance of expected');
assertMatcherError(function() {
goog.labs.testing.assertThat(5, instanceOfClass(function() {}));
}, 'instanceOfClass does not throw exception on failure');
}
function testHasProperty() {
goog.labs.testing.assertThat({x: 1}, hasProperty('x'),
'{x:1} has property x}');
assertMatcherError(function() {
goog.labs.testing.assertThat({x: 1}, hasProperty('y'));
}, 'hasProperty does not throw exception on failure');
}
function testIsNull() {
goog.labs.testing.assertThat(null, isNull(), 'null is null');
assertMatcherError(function() {
goog.labs.testing.assertThat(5, isNull());
}, 'isNull does not throw exception on failure');
}
function testIsNullOrUndefined() {
var x;
goog.labs.testing.assertThat(undefined, isNullOrUndefined(),
'undefined is null or undefined');
goog.labs.testing.assertThat(x, isNullOrUndefined(),
'undefined is null or undefined');
x = null;
goog.labs.testing.assertThat(null, isNullOrUndefined(),
'null is null or undefined');
goog.labs.testing.assertThat(x, isNullOrUndefined(),
'null is null or undefined');
assertMatcherError(function() {
goog.labs.testing.assertThat(5, isNullOrUndefined());
}, 'isNullOrUndefined does not throw exception on failure');
}
function testIsUndefined() {
var x;
goog.labs.testing.assertThat(undefined, isUndefined(),
'undefined is undefined');
goog.labs.testing.assertThat(x, isUndefined(), 'undefined is undefined');
assertMatcherError(function() {
goog.labs.testing.assertThat(5, isUndefined());
}, 'isUndefined does not throw exception on failure');
}
function assertMatcherError(callable, errorString) {
var e = assertThrows(errorString || 'callable throws exception', callable);
assertTrue(e instanceof goog.labs.testing.MatcherError);
}
</script>
</body>
</html>