How do you unit test a binding with a different name in an Angular 1.5 component?

Daniel Smith

I have the following component:

angular.module('foo')
    .component('searchInput', {
        bindings: {
            text: "<query"
        },
        templateUrl: 'components/searchInput/searchInput.html',
        controller: 'SearchInputCtrl'
    });

For the following to pass:

expect(component.text).toBe('bar');

I have to use the following code:

    var component = $componentController('searchInput',
        {$scope: {}},
        {
            text: 'bar'
        }
    );

However, I want to test that the value being bound to 'text' is being sourced from 'query'. This does not work:

    var component = $componentController('searchInput',
        {$scope: {}},
        {
            query: 'bar'
        }
    );
rob

You can test this sort of thing by compiling the component. e.g.

inject(function($compile, $rootScope) {
    var parentScope = $rootScope.$new();
    parentScope.myVar = 'test';

    var element = angular.element('<search-input query="myVar"></search-input>');

    var compiledElement = $compile(element)(parentScope);
    parentScope.$digest();

    var scope = compiledElement.isolateScope();

    expect(scope.$ctrl.text).toBe('test');
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to mock a FormBuilder for Angular Component Unit Test

How do you unit test a Celery task?

How do you unit test a Celery task?

Angular Unit Test Error: No component factory found for Component. Did you add it to @NgModule.entryComponents

How do you Unit Test Python DataFrames

How to unit test if an angular 2 component contains another component

How do you skip a unit test in Django?

How do you unit test private methods?

How to unit test an Angular 1.5 Component template?

How to unit test (with angular 5) a component that depends on the height of an element?

Angular 5: How do I deal with the dependencies of the dependencies of a component while unit testing?

How do you unit test Django RawQuerySets

Angular 5 : How to write a Jasmine unit test for a data binding attribute

How do I unit test with a subscribe in Angular5?

Angular 5 unit test for component that calls a service

How do you moq a class for unit test

How do you unit test a Vue.js functional component with a render function that returns any array of elements?

How to write unit test for ActionsSubject subscription in Angular Component

In a React/Jest unit test, how do you simulate an event prop being called by a mocked component?

Unit test angular component with input binding and router links gives error 'Cannot read property '__source' of undefined'

How do you change state of a react component from a different component?

Angular unit test child component

ReactJS - How do you set the state of a component from a different component?

How do you use test-unit?

Angular 2 unit test for component

how to unit test an arrow function in angular 5

How to test shared component's method in Angular 2 unit testing?

How do you test django-axes with a Django unit test?

How to unit test the Slider component in mui v5