コード例 #1
0
      ['@test it does not render a main component when using a namespace']() {
        this.addTemplate(
          {
            specifier: 'template:components/main',
            namespace: 'my-addon',
          },
          'namespaced template {{myProp}}'
        );

        this.add(
          {
            specifier: 'component:main',
            namespace: 'my-addon',
          },
          Component.extend({
            myProp: 'My property',
          })
        );

        this.add(
          {
            specifier: 'helper:my-addon',
            namespace: 'empty-namespace',
          },
          helper(() => 'my helper')
        );

        this.render('{{empty-namespace::my-addon}}');

        this.assertText('my helper'); // component should be not found

        this.runTask(() => this.rerender());

        this.assertText('my helper');
      }
コード例 #2
0
    ['@test Bound helpers registered on the container can be late-invoked'](assert) {
      this.addTemplate('application', `<div id='wrapper'>{{x-reverse}} {{x-reverse foo}}</div>`);

      this.add(
        'controller:application',
        Controller.extend({
          foo: 'alex',
        })
      );

      this.application.register(
        'helper:x-reverse',
        helper(function([value]) {
          return value
            ? value
                .split('')
                .reverse()
                .join('')
            : '--';
        })
      );

      return this.visit('/').then(() => {
        assert.equal(
          this.$('#wrapper').text(),
          '-- xela',
          'The bound helper was invoked from the container'
        );
      });
    }
コード例 #3
0
ファイル: visit_test.js プロジェクト: GreatWizard/ember.js
    [`@test visit() on engine resolves engine helper`](assert) {
      assert.expect(2);

      this.router.map(function() {
        this.mount('blog');
      });

      // Register engine
      let BlogEngine = Engine.extend({
        init(...args) {
          this._super.apply(this, args);
          this.register('template:application', compile('{{swag}}'));
          this.register(
            'helper:swag',
            helper(function() {
              return 'turnt up';
            })
          );
        },
      });
      this.add('engine:blog', BlogEngine);

      // Register engine route map
      let BlogMap = function() {};
      this.add('route-map:blog', BlogMap);

      this.assertEmptyFixture();

      return this.visit('/blog', { shouldRender: true }).then(() => {
        assert.strictEqual(this.element.textContent, 'turnt up', 'Engine component is resolved');
      });
    }
コード例 #4
0
    ['@test Undashed helpers registered on the container can be invoked'](assert) {
      this.addTemplate(
        'application',
        `<div id='wrapper'>{{omg}}|{{yorp 'boo'}}|{{yorp 'ya'}}</div>`
      );

      this.application.register('helper:omg', helper(() => 'OMG'));

      this.application.register('helper:yorp', helper(([value]) => value));

      return this.visit('/').then(() => {
        assert.equal(
          this.$('#wrapper').text(),
          'OMG|boo|ya',
          'The helper was invoked from the container'
        );
      });
    }
コード例 #5
0
  registerHelper(name, funcOrClassBody) {
    let type = typeof funcOrClassBody;

    if (type === 'function') {
      this.owner.register(`helper:${name}`, helper(funcOrClassBody));
    } else if (type === 'object' && type !== null) {
      this.owner.register(`helper:${name}`, Helper.extend(funcOrClassBody));
    } else {
      throw new Error(`Cannot register ${funcOrClassBody} as a helper`);
    }
  }
コード例 #6
0
    ['@test Unbound dashed helpers registered on the container can be late-invoked'](assert) {
      this.addTemplate('application', `<div id='wrapper'>{{x-borf}} {{x-borf 'YES'}}</div>`);

      let myHelper = helper(params => params[0] || 'BORF');
      this.application.register('helper:x-borf', myHelper);

      return this.visit('/').then(() => {
        assert.equal(
          this.$('#wrapper').text(),
          'BORF YES',
          'The helper was invoked from the container'
        );
      });
    }
コード例 #7
0
    [`@test the default resolver resolves container-registered helpers via lookupFor`](assert) {
      let shorthandHelper = makeHelper(() => {});
      let helper = Helper.extend();

      this.application.register('helper:shorthand', shorthandHelper);
      this.application.register('helper:complete', helper);

      let lookedUpShorthandHelper = this.applicationInstance.factoryFor('helper:shorthand').class;

      assert.ok(lookedUpShorthandHelper.isHelperFactory, 'shorthand helper isHelper');

      let lookedUpHelper = this.applicationInstance.factoryFor('helper:complete').class;

      assert.ok(lookedUpHelper.isHelperFactory, 'complete helper is factory');
      assert.ok(helper.detect(lookedUpHelper), 'looked up complete helper');
    }
コード例 #8
0
      ['@test it renders a namespaced helper']() {
        this.add(
          {
            specifier: 'helper:my-helper',
            namespace: 'my-namespace',
          },
          helper(() => 'my helper')
        );

        this.render('{{my-namespace::my-helper}}');

        this.assertText('my helper');

        this.runTask(() => this.rerender());

        this.assertText('my helper');
      }
コード例 #9
0
    [`@test the default resolver resolves helpers on the namespace`](assert) {
      let ShorthandHelper = makeHelper(() => {});
      let CompleteHelper = Helper.extend();

      this.application.ShorthandHelper = ShorthandHelper;
      this.application.CompleteHelper = CompleteHelper;

      let resolvedShorthand = this.application.resolveRegistration('helper:shorthand');
      let resolvedComplete = this.application.resolveRegistration('helper:complete');

      assert.equal(
        resolvedShorthand,
        ShorthandHelper,
        'resolve fetches the shorthand helper factory'
      );
      assert.equal(resolvedComplete, CompleteHelper, 'resolve fetches the complete helper factory');
    }