当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript mocha.beforeEach函数代码示例

本文整理汇总了TypeScript中mocha.beforeEach函数的典型用法代码示例。如果您正苦于以下问题:TypeScript beforeEach函数的具体用法?TypeScript beforeEach怎么用?TypeScript beforeEach使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了beforeEach函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: describe

  describe('datapoint processing', () => {
    let waterrower;

    beforeEach(done => {
      waterrower = new WaterRower();
      waterrower.setupStreams();
      done();
    })

    it('treats distance as a hexadecimal integer', done => {
      waterrower.once('data', point => {
        assert.equal(point.name, 'distance');
        assert.equal(point.value, 7350);
        done();
      });
      waterrower.reads$.next({ time: 1468559128188, type: 'datapoint', data: 'IDD0571CB6\r'});
    });

    it('treats display minutes as a decimal integer', done => {
      waterrower.once('data', point => {
        assert.equal(point.name, 'display_min');
        assert.equal(point.value, 28);
        done();
      });
      waterrower.reads$.next({ time: 1468559128188, type: 'datapoint', data: 'IDS1E228\r'});
    });
  });
开发者ID:codefoster,项目名称:waterrower,代码行数:27,代码来源:test.ts

示例2: describeModule

describeModule('name', function() {
    beforeEach(function() {
    });

    it('test', function() {
    });
});
开发者ID:AlexGalays,项目名称:DefinitelyTyped,代码行数:7,代码来源:ember-mocha-tests.ts

示例3: describe

describe(relative(__filename), () =>
{
	let currentTest: ITest;

	beforeEach(function ()
	{
		currentTest = this.currentTest as ITest;

		//console.log('it:before', currentTest.title);
		//console.log('it:before', currentTest.fullTitle());
	});

	// @ts-ignore
	describe(`custom merge`, () =>
	{
		it('custom merge array', function(done) {
			var mergeFunctionCalled = false
			function overwriteMerge(target, source, options) {
				mergeFunctionCalled = true
				assert.equal(options.arrayMerge, overwriteMerge)

				return source
			}
			const destination = {
				someArray: [ 1, 2 ],
				someObject: { what: 'yes' },
			}
			const source = {
				someArray: [ 1, 2, 3 ],
			}

			const actual = merge(destination, source, { arrayMerge: overwriteMerge })
			const expected = {
				someArray: [ 1, 2, 3 ],
				someObject: { what: 'yes' },
			}

			assert.ok(mergeFunctionCalled)
			assert.deepEqual(actual, expected)
			done()
		})

		it('merge top-level arrays', function(done) {
			function overwriteMerge(a, b) {
				return b
			}
			var actual = merge([ 1, 2 ], [ 1, 2 ], { arrayMerge: overwriteMerge })
			var expected = [ 1, 2 ]

			assert.deepEqual(actual, expected)
			done()
		})

	});
});
开发者ID:bluelovers,项目名称:deepmerge,代码行数:55,代码来源:custom-array-merge.test.ts

示例4: describe

    describe('request', function() {
      beforeEach(function() {
        this.server.get('/users/1', () => jsonResponse(200, { name: 'Alex' }));
      });

      it('works without the generic defined', async function() {
        const ajax = new AjaxRequest();
        const response = await ajax.request('/users/1');

        expect(response).to.deep.equal({ name: 'Alex' });
      });

      it('can provide a generic type to resolve to', async function() {
        const ajax = new AjaxRequest();
        const response = await ajax.request<User>('/users/1');

        expect(response).to.deep.equal({ name: 'Alex' });
      });
    });
开发者ID:knownasilya,项目名称:ember-ajax,代码行数:19,代码来源:typescript-usage-test.ts

示例5: describe

describe("Environment operations", () => {
  let context: Context;
  let context2: Context;

  beforeEach(() => {
    context = consoleLoggingMetaesContext();
    context2 = consoleLoggingMetaesContext();
  });

  it("should properly serialize/deserialize primitive values in enviromnent", () => {
    const primitiveValues = { foo: "bar", a: 1, b: false };
    assert.deepEqual(environmentToMessage(context, { values: primitiveValues }), { values: primitiveValues });
  });

  it("should properly serialize/deserialize object values in enviromnent", () => {
    function fn() {}
    const obj = { fn };
    const env: Environment = { values: { fn, obj } };
    const json = environmentToMessage(context, env);
    const envBack = environmentFromMessage(context, json);
    assert.deepEqual(env, envBack);
  });

  it("should properly serialize/deserialize object values in enviromnent with multiple contexts", () => {
    [context, context2].forEach(context => {
      function fn() {}
      const obj = { fn };
      const env: Environment = { values: { fn, obj } };
      const json = environmentToMessage(context, env);
      assert.equal(getReferencesMap(context).size, 2);
      const envBack = environmentFromMessage(context, json);
      assert.deepEqual(env, envBack);
      assert.equal(getReferencesMap(context).size, 2);
    });
  });

  it("should properly add values to existing environment", () => {
    const env = { values: { a: 1 } };
    const env2 = mergeValues({ b: 2 }, env);

    assert.equal(env2.values["a"], 1);
  });
});
开发者ID:metaes,项目名称:metaes,代码行数:43,代码来源:remote.spec.ts

示例6: describe

describe("Evaluation", () => {
  let context: Context;
  beforeEach(() => {
    context = new MetaesContext();
  });
  it("success continuation should be called", () => new Promise(resolve => context.evaluate("2", resolve)));

  it("error continuation should be called", () => new Promise(resolve => context.evaluate("throw 1;", null, resolve)));

  it("should not throw in current callstack", () => {
    expect(() => context.evaluate("throw 1;")).to.not.throw();
  });

  it("should correctly execute scripting context", async () => {
    assert.equal(await evalFunctionBodyAsPromise({ context, source: a => a * 2 }, { values: { a: 1 } }), 2);
  });

  it("should correctly execute cooperatively", async () => {
    [1, 2, 3, 4, 5, 6].forEach(async i =>
      assert.equal(await evalFunctionBodyAsPromise({ context, source: a => a * 2 }, { values: { a: i } }), i * 2)
    );
  });
});
开发者ID:metaes,项目名称:metaes,代码行数:23,代码来源:metaes.spec.ts

示例7: describe

describe("Example Proxy implementation", async () => {
  type Handler = {
    get?(target, name): any;
    set?(obj, prop, value): Boolean;
  };
  class Proxy {
    constructor(public target: any, public handler: Handler) {}
  }

  let interpreters = {
    values: {
      GetProperty({ object, property }, c) {
        if (object instanceof Proxy && object.handler.get) {
          c(object.handler.get(object.target, property));
        } else {
          GetProperty.apply(null, arguments);
        }
      },
      SetProperty({ object, property, value }, c, cerr) {
        if (object instanceof Proxy && object.handler.set) {
          try {
            c(object.handler.set(object.target, property, value));
          } catch (e) {
            cerr(e);
          }
        } else {
          SetProperty.apply(null, arguments);
        }
      }
    },
    prev: ECMAScriptInterpreters
  };

  const ERROR_MESSAGE = "Can't write to proxied object";
  let context: MetaesContext;

  beforeEach(() => {
    let value = { a: 1, b: 2 };
    let proxied = new Proxy(value, {
      get(object, property) {
        return object[property] + "mln";
      },
      set() {
        throw new Error(ERROR_MESSAGE);
      }
    });
    let self = { value, proxied };
    context = new MetaesContext(undefined, undefined, { values: { self, console } }, { interpreters });
  });

  it("should support standard get operations", async () => {
    assert.deepEqual(await evalFunctionBodyAsPromise({ context, source: self => [self.value.a, self.value.b] }), [
      1,
      2
    ]);
  });

  it("should support custom get operations", async () => {
    assert.deepEqual(await evalFunctionBodyAsPromise({ context, source: self => [self.proxied.a, self.proxied.b] }), [
      "1mln",
      "2mln"
    ]);
  });

  it("should support custom set operations", async () => {
    try {
      await context.evalFunctionBody(self => {
        self.proxied.a = "a new value";
      });
    } catch (e) {
      assert.equal(e.value.message, ERROR_MESSAGE);
    }
  });
});
开发者ID:metaes,项目名称:metaes,代码行数:74,代码来源:interpreters.spec.ts


注:本文中的mocha.beforeEach函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。