Monday, 1 April 2019

Cannot compare enums in jasmine after angular migration from 6 to 7

I am in the process of migrating an Angular application from v6 to v7. All is well except any test that compares enums. When I run my tests, I get many errors regarding my enums like so

ERROR in src/.../some-thing.component.spec.ts: error TS2345: Argument of type 'PlanDuration.SixMonths' is not assignable to parameter of type 'Expected<PlanDuration.TwelveMonths>'.

An example of test being run looks like this:

export enum PlanDuration {
  SixMonths,
  TwelveMonths
}

...
    it('should toggle plan duration to six months if the event source id is the toggle duration and the event is not checked', () => {

      component.selectedPlanDuration = PlanDuration.TwelveMonths;
      component.handleToggle(event);
      expect(component.selectedPlanDuration).toBe(PlanDuration.SixMonths); // Tests cannot run because of errors here
    });

However, if I cast my enum to number, my tests work perfectly! This would be less than ideal to update my specs everywhere like this:

expect(component.selectedPlanDuration).toBe(<number> PlanDuration.SixMonths);

I'm unsure if I missed something in my package.json. I've compared a fresh angular 7 project to my own projects and the versions of angular core, typescript, jasmine and karma between them are the same.

How can I get my tests to compare enums properly? Below is my package.json

"dependencies": {
    "@angular/animations": "~7.2.0",
    "@angular/common": "~7.2.0",
    "@angular/compiler": "~7.2.0",
    "@angular/core": "~7.2.0",
    "@angular/forms": "~7.2.0",
    "@angular/http": "~7.2.0",
    "@angular/platform-browser": "~7.2.0",
    "@angular/platform-browser-dynamic": "~7.2.0",
    "@angular/router": "~7.2.0",
    "core-js": "^2.5.4",
    "rxjs": "~6.4.0",
    "tslib": "^1.9.0",
    "zone.js": "~0.8.26",
    "@angular/cdk": "^7.0.3",
    "@angular/flex-layout": "7.0.0-beta.24",
    "@angular/material": "7.3.6",
    "hammerjs": "2.0.8",
    "intl": "1.2.5",
    "jshashes": "1.0.7",
    "lodash-es": "4.17.11",
    "request-promise-native": "1.0.5",
    "stream": "0.0.2",
    "timers": "0.1.1",
    "url-search-params-polyfill": "5.0.0",
    "xml2js": "0.4.19"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.13.0",
    "@angular/cli": "~7.3.7",
    "@angular/compiler-cli": "~7.2.0",
    "@angular/language-service": "~7.2.0",
    "@types/node": "~8.9.4",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~3.2.2",
    "@types/lodash-es": "4.17.1",
    "gulp": "3.9.1",
    "gulp-stylelint": "7.0.0",
    "jasmine-data-provider": "2.2.0",
    "karma-cli": "1.0.1",
    "karma-junit-reporter": "1.2.0",
    "karma-parallel": "0.3.0",
    "karma-spec-reporter": "0.0.32",
    "lodash": "4.17.11",
    "moment": "2.22.2",
    "npm": "6.0.0",
    "protractor-beautiful-reporter": "1.2.5",
    "protractor-jasmine2-screenshot-reporter": "0.5.0",
    "stylelint": "9.6.0",
    "stylelint-order": "1.0.0",
    "tslint-jasmine-noSkipOrFocus": "1.0.9"
  }



from Cannot compare enums in jasmine after angular migration from 6 to 7

Query neighboring cells' cell-ids in android for 4G

I am interested in using mobile phones for conducting network field tests - i.e. collecting information about signal strength as well as other related values for a mobile network, in particular for 4G-LTE-networks.

There are a couple of applications already out there which can do this, e.g. GNet-Track (https://play.google.com/store/apps/details?id=com.gyokovsolutions.gnettracklite)

These apps are using the TelephonyManager's getAllCellInfo() to retrieve information for the serving cell (the cell to which the mobile is connected to) as well as for neighboring cells (cells that the mobile can detect but is not connected to).

Depending on the mobile phone (e.g. http://www.gyokovsolutions.com/survey/surveyresults.php) as well as on the connection technology (3G, 4G, etc.), more or less information is retrieved with getAllCellInfo(). E.g. some phones do not report information about neighboring cells at all, while other might only report the strength of the signal, etc.

From a CellInfo object, one can retrieve the identity of the cell via getCellIdentity() (to be precise, it's getCellIdentityLte(), getCellIdentityGsm() etc. in dependence of the used network technology).

The CellIdentityLte object contains (or at least should contain) the values mcc, mnc and ci (cell-identity), which can be used to identify a cell globally (computing the ecgi).

Now, the problem I am facing is that every phone that I have encountered so far (e.g. OnePlus-Three, Samsung S7) is unable to report the cell-identity of the neighboring cells (instead UNAVAILABLE (=2147483647) is returned). Other values are available, e.g. the field PCI of the LTECellIdendity of the neighboring cells were available.

My question is: Has anyone encountered mobile phones which are able to report the cell-identity of neighboring cells in a 4G-network?

This seems to be a recurring problem (the linked discussions concern other technologies, but face the same problem):



from Query neighboring cells' cell-ids in android for 4G

Warning when using dagger: "@Component.Builder has setters for modules or components that aren't required"

I'm trying to implement new features using Dagger.

My code

object File {

    lateinit var component: Component

    fun initialize(@NotNull context: Context) {


        component = DaggerFile_Component
            .builder()
            .context(context)
            .build()

    }

    @dagger.Component(modules = [Module::class])

    interface Component {
        fun uploadFile(): UploadFile
        fun awsService(): AwsService
        fun glideLoad(): GlideLoad

        @dagger.Component.Builder
        interface Builder {
            @BindsInstance
            fun context(context: Context): Builder

            fun build(): Component
        }

    }


    @dagger.Module
    internal abstract class Module {

        @Binds
        internal abstract fun bindUploadFile(uploadFileImp: UploadFileImp): UploadFile

        @Binds
        internal abstract fun bindAwsService(awsServiceImp: AwsServiceImp): AwsService

        @Binds
        internal abstract fun bindGlideLoad(glideLoadImp: GlideLoadImp): GlideLoad
    }
}

While building the project I get:

@Component.Builder has setters for modules or components that aren't required

Any help is really appreciated.



from Warning when using dagger: "@Component.Builder has setters for modules or components that aren't required"