sku-pg
Version:
Skulpt is a Javascript implementation of Python 2.x. Python that runs in your browser!
66 lines (57 loc) • 1.92 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>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Closure Unit Tests - goog.labs.observe.Observer</title>
<script src="../../base.js"></script>
<script>
goog.require('goog.labs.observe.Notice');
goog.require('goog.labs.observe.Observer');
goog.require('goog.testing.jsunit');
goog.require('goog.testing.recordFunction');
</script>
</head>
<body>
<script>
var TYPE = 'testtype';
function testToObserver() {
var expectedScope = this;
var notice = new goog.labs.observe.Notice(null, TYPE);
var fn = goog.testing.recordFunction(function(n) {
assertEquals('Function receives wrong notice object.', notice, n);
assertEquals('Function is executed with wrong scope.', expectedScope, this);
});
var observer = goog.labs.observe.Observer.fromFunction(fn);
observer.notify(notice);
assertEquals(1, fn.getCallCount());
}
function testToObserverWithScope() {
var expectedScope = {};
var notice = new goog.labs.observe.Notice(null, TYPE);
var fn = goog.testing.recordFunction(function(n) {
assertEquals('Function receives wrong notice object.', notice, n);
assertEquals('Function is executed with wrong scope.', expectedScope, this);
});
var observer = goog.labs.observe.Observer.fromFunction(fn, expectedScope);
observer.notify(notice);
assertEquals(1, fn.getCallCount());
}
function testToObserverEquals() {
var fn = function() {};
assertTrue(
goog.labs.observe.Observer.fromFunction(fn).equals(
goog.labs.observe.Observer.fromFunction(fn)));
var scope = {};
assertTrue(
goog.labs.observe.Observer.fromFunction(fn, scope).equals(
goog.labs.observe.Observer.fromFunction(fn, scope)));
}
</script>
</body>