How to use the mocha.beforeEach function in mocha

To help you get started, we’ve selected a few mocha examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github linxmix / linx / tests / helpers / setup-test-environment.js View on Github external
export default function() {
  startApp();
  beforeEach(setProperties);
  setupWebAudioStub();

  afterEach(function(done) {
    // TODO(DBSTUB)
    // reset firebase
    this.timeout(5000);
    let firebase = this.container.lookup('service:firebase');
    firebase.remove(done);
  });
}
github cucumber / cucumber-js / src / support_code_library_builder / index_spec.js View on Github external
describe('multiple', () => {
      beforeEach(function() {
        this.hook1 = function hook1() {}
        this.hook2 = function hook2() {}
        supportCodeLibraryBuilder.reset('path/to/project', uuid())
        supportCodeLibraryBuilder.methods.Before(this.hook1) // eslint-disable-line babel/new-cap
        supportCodeLibraryBuilder.methods.Before(this.hook2) // eslint-disable-line babel/new-cap
        this.options = supportCodeLibraryBuilder.finalize()
      })

      it('adds the scenario hook definitions in the order of definition', function() {
        expect(this.options.beforeTestCaseHookDefinitions).to.have.lengthOf(2)
        expect(this.options.beforeTestCaseHookDefinitions[0].code).to.eql(
          this.hook1
        )
        expect(this.options.beforeTestCaseHookDefinitions[1].code).to.eql(
          this.hook2
        )
github alexandercerutti / node-telegram-keyboard-wrapper / test / replyKeyboard.ts View on Github external
describe(".addRow(...keys)", () => {
		let keyboard;

		beforeEach("init keyboard", () => {
			keyboard = new ReplyKeyboard();
		});

		it("Should add elements to a row and return the right number of rows via .extract() method", () => {
			keyboard
				.addRow(...firstLoad)
				.addRow(...secondLoad);

			assert.equal(keyboard.length, 2);
		});

		it("Should have a length property after .addRow(), which returns the amount of rows", () => {
			assert.equal(keyboard.addRow(...thirdLoad).length, 1);
		});
	});
github LucasBassetti / react-simple-chatbot / tests / lib / speechSynthesis.spec.js View on Github external
describe('speak', () => {
    const speakSpy = spy();

    beforeEach(() => {
      global.window.speechSynthesis = {
        speak: speakSpy,
      };
      global.window.SpeechSynthesisUtterance = function SpeechSynthesisUtterance() {};
    });

    afterEach(() => {
      speakSpy.resetHistory();
    });

    it('should not speak if disabled', () => {
      const speak = speakFn({ enable: false });
      speak({});
      expect(speakSpy.called).to.eql(false);
    });
github ciena-blueplanet / ember-prop-types / tests / helpers / validator.js View on Github external
export function itValidatesTheProperty (ctx, throwErrors, ...warningMessages) {
  let def, instance, propertyName

  beforeEach(function () {
    def = ctx.def
    instance = ctx.instance
    propertyName = ctx.propertyName
  })

  it('should validate prop-types for instance', function () {
    expect(helpers.validatePropTypes).to.have.been.calledWith(instance)
  })

  it(`should validate the property "${ctx.propertyName}"`, function () {
    expect(helpers.validateProperty).to.have.been.calledWith(instance, propertyName, def)
  })

  if (throwErrors) {
    if (warningMessages.length > 0) {
      it('should throw errors', function () {
github wbyoung / babel-plugin-transform-postcss / test / postcss-server.js View on Github external
describe('with a missing config file', () => {
      let response;

      beforeEach(() => stub(path, 'dirname').callsFake(() => process.cwd()));
      afterEach(() => path.dirname.restore());

      beforeEach(async() => {
        response = await sendMessage({
          cssFile: join(__dirname, 'fixtures', 'simple.css'),
          config: join('fixtures', 'nofile'),
        });
      });
      beforeEach(closeStderr);

      it('does not contain a response', () => {
        expect(response).to.eql('');
      });

      it('logs a useful message', () => {
        expect(fs.readFileSync(testOutput, 'utf8'))
          .to.match(/No PostCSS Config/i);
      });
    });
  });
github luckymarmot / Paw-cURLImporter / src / TestUtils.js View on Github external
describe(Class.name.replace(/Test$/, ''), () => {
        before(test.setUpClass.bind(test))
        after(test.tearDownClass.bind(test))
        beforeEach(test.setUp.bind(test))
        afterEach(test.tearDown.bind(test))

        for (let fname of Object.keys(tests)) {
            it(fname, tests[fname].bind(test))
        }
    })
}