mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +08:00

* chore: move tns-core-modules to nativescript-core * chore: preparing compat generate script * chore: add missing definitions * chore: no need for http-request to be private * chore: packages chore * test: generate tests for tns-core-modules * chore: add anroid module for consistency * chore: add .npmignore * chore: added privateModulesWhitelist * chore(webpack): added bundle-entry-points * chore: scripts * chore: tests changed to use @ns/core * test: add scoped-packages test project * test: fix types * test: update test project * chore: build scripts * chore: update build script * chore: npm scripts cleanup * chore: make the compat pgk work with old wp config * test: generate diff friendly tests * chore: create barrel exports * chore: move files after rebase * chore: typedoc config * chore: compat mode * chore: review of barrels * chore: remove tns-core-modules import after rebase * chore: dev workflow setup * chore: update developer-workflow * docs: experiment with API extractor * chore: api-extractor and barrel exports * chore: api-extractor configs * chore: generate d.ts rollup with api-extractor * refactor: move methods inside Frame * chore: fic tests to use Frame static methods * refactor: create Builder class * refactor: use Builder class in tests * refactor: include Style in ui barrel * chore: separate compat build script * chore: fix tslint errors * chore: update NATIVESCRIPT_CORE_ARGS * chore: fix compat pack * chore: fix ui-test-app build with linked modules * chore: Application, ApplicationSettings, Connectivity and Http * chore: export Trace, Profiling and Utils * refactor: Static create methods for ImageSource * chore: fix deprecated usages of ImageSource * chore: move Span and FormattedString to ui * chore: add events-args and ImageSource to index files * chore: check for CLI >= 6.2 when building for IOS * chore: update travis build * chore: copy Pod file to compat package * chore: update error msg ui-tests-app * refactor: Apply suggestions from code review Co-Authored-By: Martin Yankov <m.i.yankov@gmail.com> * chore: typings and refs * chore: add missing d.ts files for public API * chore: adress code review FB * chore: update api-report * chore: dev-workflow for other apps * chore: api update * chore: update api-report
61 lines
2.1 KiB
TypeScript
61 lines
2.1 KiB
TypeScript
import { Observable } from "@nativescript/core/data/observable";
|
|
import { assert } from "chai";
|
|
|
|
describe("observable", () => {
|
|
describe("once", () => {
|
|
|
|
let observable: Observable;
|
|
let handler: () => void;
|
|
let callCount: number = 0;
|
|
|
|
beforeEach("create handlers", () => {
|
|
handler = function() {
|
|
callCount++;
|
|
}
|
|
observable = new Observable();
|
|
observable.once("test", handler);
|
|
});
|
|
afterEach("reset handlers", () => {
|
|
callCount = 0;
|
|
handler = null;
|
|
observable = null;
|
|
});
|
|
|
|
function notify() {
|
|
observable.notify({ eventName: "test", object: observable });
|
|
}
|
|
function notifyWrong() {
|
|
observable.notify({ eventName: "test2", object: observable });
|
|
}
|
|
|
|
it("fires just once", () => {
|
|
notify();
|
|
notify();
|
|
assert.equal(callCount, 1, "Expected the handler to be called exactly once");
|
|
});
|
|
it("does not fire for other events", () => {
|
|
notifyWrong();
|
|
assert.equal(callCount, 0, "Expected the handler to not be called, when other events fire");
|
|
});
|
|
});
|
|
|
|
describe("once", () => {
|
|
it("fire once when fired recursively", () => {
|
|
const observable = new Observable();
|
|
let callCount1 = 0;
|
|
let callCount2 = 0;
|
|
const handler2 = function () {
|
|
callCount2++;
|
|
}
|
|
const handler1 = function () {
|
|
callCount1++;
|
|
observable.once("test", handler2);
|
|
observable.notify({ eventName: "test", object: observable });
|
|
}
|
|
observable.once("test", handler1);
|
|
observable.notify({ eventName: "test", object: observable });
|
|
assert.equal(callCount1, 1, "Expected the first handler to unsubscribe before being fired and to notify just once");
|
|
assert.equal(callCount2, 1, "Expected the second handler to be fired once when recursively notified by the first handler");
|
|
});
|
|
});
|
|
}); |