<commit_before>import expect from 'must';

import debounce from './debounce';

// ===================================================================

class Editor {

  counter = 0;

  @debounce(500)
  updateCounter1() {
    this.counter++;
  }

  @debounce(500, true)
  updateCounter2() {
    this.counter++;
  }
}

// ===================================================================

describe('debounce', function () {

  let editor;

  beforeEach(function() {
    editor = new Editor();
  });

  it('invokes function only once', function (done) {

    editor.updateCounter1();
    expect(editor.counter).to.equal(0);

    setTimeout(() => {
      expect(editor.counter).to.equal(1);
      done();
    }, 600);
  });

  it('invokes function immediately and only once if "immediate" option is true', function (done) {

    editor.updateCounter2();
    expect(editor.counter).to.equal(1);

    setTimeout(() => {
      expect(editor.counter).to.equal(1);
      done();
    }, 400);
  });

})<commit_msg>Fixed tests to use chai expect.<commit_after>import { default as chai, expect } from 'chai';
import debounce from './debounce';

// ===================================================================

class Editor {

  counter = 0;

  @debounce(500)
  updateCounter1() {
    this.counter++;
  }

  @debounce(500, true)
  updateCounter2() {
    this.counter++;
  }
}

// ===================================================================

describe('debounce', function () {

  let editor;

  beforeEach(function () {
    editor = new Editor();
  });

  it('invokes function only once', function (done) {

    editor.updateCounter1();
    editor.counter.should.equal(0);

    setTimeout(() => {
      editor.counter.should.equal(1);
      done();
    }, 600);
  });

  it('invokes function immediately and only once if "immediate" option is true', function (done) {

    editor.updateCounter2();
    editor.counter.should.equal(1);

    // should still be 1 because 600ms hasn't yet passed
    setTimeout(() => {
      editor.counter.should.equal(1);
      done();
    }, 400);
  });

})
{'fraction_non_alphanumeric': 0.2719885277246654, 'fraction_numerical': 0.02198852772466539, 'mean_word_length': 3.4914163090128754, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '74172', 'n_tokens_mistral': 657, 'n_tokens_neox': 585, 'n_words': 133}