Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to share global variables in jest test

I would like to use variable Shopresult in jest test. this variable will be defined in beforeAll section.

describe("test",()=>{
    
    let Shopresult:Shop;

    beforeAll(async()=>{
        await getConnection(LocalOrmconfig).then(async()=>{
          const Shopresult = await getRepository(Shop).save(mockData)
        })
    })
    afterAll(async()=>{
        await getConnection(LocalOrmconfig).then(async()=>{
            await getRepository(PricingPattern)
            .createQueryBuilder()
            .delete()
            .where({shopId:Shopresult.shopId})
            .execute()
        })
    })
    

But above code invoked following error.

'Shopresult' is declared but its value is never read.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

What is the root cause of this?
I declared them in let clause.

If someone has opinion,will you please let me know. thanks

>Solution :

The problem is with this line. it is not using the Shopresult defined outside but creating a new variable. Remove the const keyword

const Shopresult = await getRepository(Shop).save(mockData)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading