Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@truesparrow/common-js / dev-only-test.js
Size: Mime:
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = require("chai");
require("mocha");
const dev_only_1 = require("./dev-only");
const env_1 = require("./env");
describe('devOnly', () => {
    class X {
        localFn() { return 'A'; }
        localFn2Args(x, y) { return x + y; }
        localFn1ArgAndThis(x) { return x + this.y; }
        testFn() { return 'B'; }
        stagingFn() { return 'C'; }
        prodFn() { return 'D'; }
    }
    __decorate([
        dev_only_1.devOnly(env_1.Env.Local)
    ], X.prototype, "localFn", null);
    __decorate([
        dev_only_1.devOnly(env_1.Env.Local)
    ], X.prototype, "localFn2Args", null);
    __decorate([
        dev_only_1.devOnly(env_1.Env.Local)
    ], X.prototype, "localFn1ArgAndThis", null);
    __decorate([
        dev_only_1.devOnly(env_1.Env.Test)
    ], X.prototype, "testFn", null);
    __decorate([
        dev_only_1.devOnly(env_1.Env.Staging)
    ], X.prototype, "stagingFn", null);
    __decorate([
        dev_only_1.devOnly(env_1.Env.Live)
    ], X.prototype, "prodFn", null);
    it('should allow calling when the environment is local', () => {
        const x = new X();
        chai_1.expect(x.localFn()).to.eql('A');
    });
    it('should preserve arguments when the environment is local', () => {
        const x = new X();
        chai_1.expect(x.localFn2Args(10, 30)).to.eql(40);
    });
    it('should preserve arguments and this when environment is local', () => {
        const x = new X();
        x.y = 10;
        chai_1.expect(x.localFn1ArgAndThis(30)).to.eql(40);
        x.y = 30;
        chai_1.expect(x.localFn1ArgAndThis(30)).to.eql(60);
    });
    it('should allow calling when the environment is test', () => {
        const x = new X();
        chai_1.expect(x.testFn()).to.eql('B');
    });
    it('should allow calling when the environment is staging', () => {
        const x = new X();
        chai_1.expect(x.stagingFn()).to.eql('C');
    });
    it('should throw when the environment is prod', () => {
        const x = new X();
        chai_1.expect(() => x.prodFn()).to.throw('Calling dev only code in a non-dev environment');
    });
});
//# sourceMappingURL=dev-only-test.js.map