{"size": 1891, "ext": "js", "max_stars_repo_path": "modules/nuclide-commons-atom/__atom_tests__/feature-config-test.js", "max_stars_repo_name": "aaronabramov/atom-ide-ui", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "modules/nuclide-commons-atom/__atom_tests__/feature-config-test.js", "max_issues_repo_name": "aaronabramov/atom-ide-ui", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "modules/nuclide-commons-atom/__atom_tests__/feature-config-test.js", "max_forks_repo_name": "aaronabramov/atom-ide-ui", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 30.5, "max_line_length": 78, "alphanum_fraction": 0.6451612903}
/**
 * Copyright (c) 2017-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 *
 * @flow strict-local
 * @format
 */

import featureConfig from '../feature-config';

describe('main', () => {
  it('returns numbers when numbers are set', () => {
    featureConfig.set('foobar', 5);
    expect(featureConfig.get('foobar')).toEqual(5);
  });

  it('returns booleans when numbers are set', () => {
    featureConfig.set('cat', true);
    expect(featureConfig.get('cat')).toEqual(true);
  });

  it('passes values to observers on change', () => {
    const spy = jest.fn();
    featureConfig.observe('animal', spy);
    featureConfig.set('animal', 'yup');
    expect(spy).toHaveBeenCalled();
  });

  it('can observeAsStream', () => {
    const spy = jest.fn();
    featureConfig.observeAsStream('animal').subscribe(spy);
    featureConfig.set('animal', 'yup');
    expect(spy).toHaveBeenCalled();
  });

  it('passes options to observe', () => {
    const spy = jest.fn();
    featureConfig.observe('animal', {scope: []}, spy);
    featureConfig.set('animal', 'yup');
    expect(spy).toHaveBeenCalled();
  });

  it('calls callbacks passed to `onDidChange`', () => {
    const spy = jest.fn();
    featureConfig.onDidChange('mars.attacks', spy);
    featureConfig.set('mars.attacks', 42);
    expect(spy).toHaveBeenCalled();
  });

  it('resets to defaults with "unset"', () => {
    featureConfig.setSchema('purple.pants', {type: 'number', default: 15});
    featureConfig.set('purple.pants', 25);
    expect(featureConfig.get('purple.pants')).toEqual(25);
    featureConfig.unset('purple.pants');
    expect(featureConfig.get('purple.pants')).toEqual(15);
  });
});
