简体   繁体   中英

Testing with Jasmine Sequelize TypeError: _models2.default.count is not a function

I am trying to test my Database using Jasmine. I am using PostgreSQL with Sequelize. The model I am testing is:

fishtype.js

import { sequelize, DataTypes } from '.';

const FishType = sequelize.define(
  'FishType',
  {
    name: {
      type: DataTypes.STRING(50),
      allowNull: false,
      unique: 'fishType_unique'
    }
  }
)

FishType.associate = function ({ FishingSpot }) {
  FishType.hasMany(FishingSpot, {
    foreignKey: {
      name: 'fishingSpotId',
      allowNull: true
    },
    as: 'fishingSpots',
  })
}

export default FishType;

My spec.js file is:

fishtype.spec.js

import FishType from '../../models';

describe('FishType', () => {
  it('should be accessed', () => {
   console.log(FishType.count())
   return FishType.count().then((count) => {
     expect(count).toEqual(0);
   });
 });
})  

After starting the testing I get the following error:

    Failures:
1) FishType should be accessed
  Message:
    TypeError: _models2.default.count is not a function
  Stack:
        at <Jasmine>
        at UserContext.<anonymous> (E:/js/fishing-app/server/spec/model/fishType.spec.js:6:26)
    at <Jasmine>
    at runCallback (timers.js:810:20)
    at tryOnImmediate (timers.js:768:5)
    at processImmediate [as _immediateCallback] (timers.js:745:5)

我在models文件夹中缺少index.js文件,并且模型本身对序列化不可见

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM