mardi 30 mai 2017

Testing Angular 1.x Component using ES6 doesn't load bindings using $componentController

I have the following code

My component

class PaginationController{
    page = 1

    constructor() {
        console.log(this) // PaginationController {page: 1}
    }
}
export const PaginationComponent = {
  templateUrl: '/components/app/views/pagination.html',
  controller: PaginationController,
  controllerAs: '$ctrl',
  bindings: {
      data: '=',
      size: '<',
  }
}

Test

import { PaginationComponent } from '../src/components/app/pagination'

describe("Pagination Controller", () => {

    let controller

    beforeEach(() => {
        angular
          .module("Test", [])
          .component('pagination', PaginationComponent)
    })

    beforeEach(window.module("Test"))

    beforeEach(inject(($componentController) => {
        controller = $componentController('pagination', null, {
            data: [],
            size: 10
        })
    }))

    it("change page", () => {
        console.log(controller)
    })
})

I expect that the console.log on the contructor in the controller prints PaginationController {page: 1, data: [], size: 10} but i get PaginationController {page: 1}, so i assume that the binding is not working.

Anybody can help me to understand why?

Aucun commentaire:

Enregistrer un commentaire