const testPlugin = require('./testPlugin');

describe('__() errors', () => {
  test('throwing error for missing value', () => {
    const code = '__("missing")';
    const translations = {};
    expect(() => testPlugin(code, translations)).toThrowError(/missing/);
  });

  test('tells what part is missing', () => {
    const code = '__("exists.missing.more")';
    const translations = { exists: { foo: 'bar' } };
    expect(() => testPlugin(code, translations)).toThrowError(/'missing'/);
  });

  test('does not allow objects to come through', () => {
    const code = '__("this_should_be_string")';
    const translations = { this_should_be_string: { but: 'it is not' } };
    expect(() => testPlugin(code, translations)).toThrowError(/incorrect type.*'object'/);
  });

  test('does not allow arrays to come through', () => {
    const code = '__("this_should_be_string")';
    const translations = { this_should_be_string: ['but it is an array'] };
    expect(() => testPlugin(code, translations)).toThrowError(/incorrect type/);
  });

  test('does not allow functions to come through', () => {
    const code = '__("this_should_be_string")';
    const translations = { this_should_be_string: () => 'but it is a function' };
    expect(() => testPlugin(code, translations)).toThrowError(/incorrect type.*'function'/);
  });
});

@@ -1325,12 +1325,892 @@
 ;%0A  %7D);%0A%7D);%0A
+%0A%0Adescribe('__obj() errors', () =%3E %7B%0A  test('throwing error for missing value', () =%3E %7B%0A    const code = '__obj(%22missing%22)';%0A    const translations = %7B%7D;%0A    expect(() =%3E testPlugin(code, translations)).toThrowError(/missing/);%0A  %7D);%0A%0A  test('tells what part is missing', () =%3E %7B%0A    const code = '__obj(%22exists.missing.more%22)';%0A    const translations = %7B exists: %7B foo: 'bar' %7D %7D;%0A    expect(() =%3E testPlugin(code, translations)).toThrowError(/'missing'/);%0A  %7D);%0A%0A  %5B%0A    %7B type: 'string', value: 'incorrectly string' %7D,%0A    %7B type: 'number', value: 123 %7D,%0A    %7B type: 'boolean', value: false %7D,%0A    %7B type: 'null', value: null %7D,%0A  %5D.map((%7B type, value %7D) =%3E %7B%0A    test(%60does not allow $%7Btype%7D to come through%60, () =%3E %7B%0A      const code = '__obj(%22key%22)';%0A      const translations = %7B key: value %7D;%0A      expect(() =%3E testPlugin(code, translations)).toThrow();%0A    %7D);%0A  %7D);%0A%7D);%0A

Add tests for __obj() errors