source: frontend/node_modules/@sinonjs/commons/lib/deprecated.test.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 13 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 3.4 KB
Line 
1/* eslint-disable no-console */
2"use strict";
3
4var assert = require("@sinonjs/referee-sinon").assert;
5var sinon = require("@sinonjs/referee-sinon").sinon;
6
7var deprecated = require("./deprecated");
8
9var msg = "test";
10
11describe("deprecated", function () {
12 describe("defaultMsg", function () {
13 it("should return a string", function () {
14 assert.equals(
15 deprecated.defaultMsg("sinon", "someFunc"),
16 "sinon.someFunc is deprecated and will be removed from the public API in a future version of sinon."
17 );
18 });
19 });
20
21 describe("printWarning", function () {
22 beforeEach(function () {
23 sinon.replace(process, "emitWarning", sinon.fake());
24 });
25
26 afterEach(sinon.restore);
27
28 describe("when `process.emitWarning` is defined", function () {
29 it("should call process.emitWarning with a msg", function () {
30 deprecated.printWarning(msg);
31 assert.calledOnceWith(process.emitWarning, msg);
32 });
33 });
34
35 describe("when `process.emitWarning` is undefined", function () {
36 beforeEach(function () {
37 sinon.replace(console, "info", sinon.fake());
38 sinon.replace(console, "log", sinon.fake());
39 process.emitWarning = undefined;
40 });
41
42 afterEach(sinon.restore);
43
44 describe("when `console.info` is defined", function () {
45 it("should call `console.info` with a message", function () {
46 deprecated.printWarning(msg);
47 assert.calledOnceWith(console.info, msg);
48 });
49 });
50
51 describe("when `console.info` is undefined", function () {
52 it("should call `console.log` with a message", function () {
53 console.info = undefined;
54 deprecated.printWarning(msg);
55 assert.calledOnceWith(console.log, msg);
56 });
57 });
58 });
59 });
60
61 describe("wrap", function () {
62 // eslint-disable-next-line mocha/no-setup-in-describe
63 var method = sinon.fake();
64 var wrapped;
65
66 beforeEach(function () {
67 wrapped = deprecated.wrap(method, msg);
68 });
69
70 it("should return a wrapper function", function () {
71 assert.match(wrapped, sinon.match.func);
72 });
73
74 it("should assign the prototype of the passed method", function () {
75 assert.equals(method.prototype, wrapped.prototype);
76 });
77
78 context("when the passed method has falsy prototype", function () {
79 it("should not be assigned to the wrapped method", function () {
80 method.prototype = null;
81 wrapped = deprecated.wrap(method, msg);
82 assert.match(wrapped.prototype, sinon.match.object);
83 });
84 });
85
86 context("when invoking the wrapped function", function () {
87 before(function () {
88 sinon.replace(deprecated, "printWarning", sinon.fake());
89 wrapped({});
90 });
91
92 it("should call `printWarning` before invoking", function () {
93 assert.calledOnceWith(deprecated.printWarning, msg);
94 });
95
96 it("should invoke the passed method with the given arguments", function () {
97 assert.calledOnceWith(method, {});
98 });
99 });
100 });
101});
Note: See TracBrowser for help on using the repository browser.