Closed ASYB closed 7 years ago
Looks like maybe your response is g-zipped, and the current version of Frisby.js does not un-gzip response bodies by default.
It is not g-zipped, since for other responses it is displaying properly, this kind of response is coming only for 201...
1.By using expectJSON(...) You are asking frisby to convert the response body into JSON and compare it with the expected JSON body. However, the body you received(as per the error) is not plain JSON, so the expectJSON fails.
2.By using .after(function()) This internally converts the response body into JSON. So the above issue repeats.
3.You mentioned, expectJSON(201). This is not how you need to expect a http status 201. (if that is what you are trying to do ) You need to use expectStatus(201). If this is not what you want.. Then let me know what you meant by expectJSON(201)
4.You mentioned that the response is not gzipped by stating..
It is not g-zipped, since for other responses it is displaying properly,
this kind of response is coming only for 201...
I did not understand this statement. By seeing the error response, i think it is gzip (inflate / deflate).
5.To understand what is the response body, You may use the below in your test and share the response
.inspectBody()
There are different ways to decompress raw buffer using different libraries., and then assert on the responses.
~ Sasi
Closing since there has been no response from the OP. Please try this in v2.
When ever my Api response 201, afterJSON(function(json)) is throwing an error below
Error: Error parsing JSON string: Unexpected token Given: ���TJL�-.�M�+Q�R���������TJI-N.�,(���S�RP v˧g���%8g$���hE�ª�(1/%$�$1$j�ga�&�MS>�+�) !4O$V���3����4B��KLI)J-.����$�ɩT��WZ I�)0�30��p.-J�K�) ���Bv��JI�99�y��P���[͍-�� MM����TJ�,��/��<??& ��"�ӡbi�E�%~����*�H�̆J�$"đ��T�
�����d��K���s\K�����S)jV$H|SK2
��T*K�)K��b�D�9�(�o�Z�tc@ ��� -$
l@P�cqIbI�Q@Q~Yf^r*̟�~�)� '195�%�,gh�od�od��RQjqA~^qjH&D����X�8�,3/�$f�IyP1l�*�Z� �YJf������Fz��eZ�����\���(+@* ���̃d
����x�bl (%����t �$�1C_�^�Z(�O)M.�I-K� (����C������9������TUV��@�������Z������Y��P\�T�|�����+���(d�%甦��g���|X������J �E�: %�: �E ��/��KWH�KQ� �� ��R�X> ��99 I� �9��) �% ������%z ������K� �R�2�K��QK3��� HIfh```jjN��*B* �1IIqF~Q� j��-0�.��Lx&ǙB�=<�A9�а<�0>='?)1'�(5R����n�4 ȉ�I��� x"��[Qj�BpIb^ �s�X��SH�Ɂ����YjQqfU*RT���+�&V*����z a�9�) �p�J�J2RL,���J2�KA1.���i�1�?F�-�_O�?--�H� MMͨ٠HAJ�h� lBZ~�BIFQ~iz���Q���)�z=� �!(�JJ�3@����,% K2@�f��[����'�楚��&��ꕀ+���tC�������������}H=�ohbhjhalf_��bkn����ik��ʼn�VB�G������O��)e&���bw/ZK��5��#���19uf����d�eB��ra�܂�=��}�\���<�]�C|<]�q9,9�$1'?�T�C["�Ff��XMjEAjrIj�KjNfYjQ%�f OM�%PRAJ&��RAbRX�\*���$���S� �W�E���9�jʆ�&� ��� �KR���s��3�Jt,����JRS�A��Q�@|cldb
lajhhWQ�XT�h?��!]�� r �T�AK���9�-P
Ca��%�� '�]> ��0Գ4�=���y%�z�P�$�'���5pQ$�4 ���h䚠hG�&d�/�-+�0u!B�|� ��V~IFjQ@F>�͢�adh��
dl�khld 1P w� "�Y���Dj���o7�K~X�][��µ�(���A�e~N~zfU�(M̫U��ye�y��yɩ: I�% �� �E� �Z�$�R�4��K��s�KsKR�K��=P��#�K����?���P�� ���%{y�v��/�L�����1�� l8��Aܟ���� � P����nlA�@�ĩ�d%X���P^D��2����{�4<�'h vG�N�
5E��ٮ����$�i3;T&f���j%�Z�CP Stacktrace: Error: Error parsing JSON string: Unexpected token Given: ���TJL�-.�M�+Q�R���������TJI-N.�,(���S�RP v˧g���%8g$���hE�ª�(1/%$�$1$j�ga�&�MS>�+�) !4O$V���3����4B��KLI)J-.����$�ɩT��WZ I�)0�30��p.-J�K�) ���Bv��JI�99�y��P���[͍-�� MM����TJ�,��/��<??& ��"�ӡbi�E�%~�����H�̆J�$"đ��T�_�����d��K���s\K�����S)jV$H|SK2 (/Users/z001hgg/Documents/shaik/Service/node_modules/frisby/lib/frisby.js:950:20)
at null. (/Users/z001hgg/Documents/shaik/Service/node_modules/frisby/lib/frisby.js:1112:18)
at Timer.listOnTimeout (timers.js:92:15)
��T*K�)K��b�D�9�(�o�Z�tc@ ��� -$
l@P�cqIbI�Q@Q~Yf^r*̟�~�)� '195�%�,gh�od�od��RQjqA~^qjH&D����X�8�,3/�$f�IyP1l�*�Z� �YJf������Fz��eZ�����\���(+@* ���̃d
����x�bl (%����t �$�1C_�^�Z(�O)M.�I-K� (����C������9������TUV��@�������Z������Y��P\�T�|�����+���(d�%甦��g���|X������J �E�: %�: �E ��/��KWH�KQ� �� ��R�X> ��99 I� �9��) �% ������%z ������K� �R�2�K��QK3��� HIfh```jjN��*B* �1IIqF~Q� j��-0�.��Lx&ǙB�=<�A9�а<�0>='?)1'�(5R����n�4 ȉ�I��� x"��[Qj�BpIb^ �s�X��SH�Ɂ����YjQqfU*RT���+�&V*����z a�9�) �p�J�J2RL,���J2�KA1.���i�1�?F�-�_O�?--�H� MMͨ٠HAJ�h� lBZ~�BIFQ~iz���Q���)�z=� �!(�JJ�3@����,% K2@�f��[����'�楚��&��ꕀ+���tC�������������}H=�ohbhjhalf_��bkn����ik��ʼn�VB�G������O��)e&���bw/ZK��5��#���19uf����d�eB��ra�܂�=��}�\���<�]�C|<]�q9,9�$1'?�T�C["�Ff��XMjEAjrIj�KjNfYjQ%�f OM�%PRAJ&��RAbRX�\*���$���S� �W�E���9�jʆ�&� ��� �KR���s��3�Jt,����JRS�A��Q�@|cldb
lajhhWQ�XT�h?��!]�� r �T�AK���9�-P
Ca��%�� '�]> ��0Գ4�=���y%�z�P�$�'���5pQ$�4 ���h䚠hG�&d�/�-+�0u!B�|� ��V~IFjQ@F>�͢�adh��
dl�khld 1P w� "�Y���Dj���o7�K~X�][��µ�(���A�e~N~zfU�(M̫U��ye�y��yɩ: I�% �� �E� �Z�$�R�4��K��s�KsKR�K��=P��#�K����?���P�� ���%{y�v��/�L�����1�� l8��Aܟ���� � P����nlA�@�ĩ�d%X��_�P^D��2����{�4<�'h vG�N�
5E��ٮ����$�i3;T&f���j*%�Z�CP at _jsonParse (/Users/z001hgg/Documents/shaik/Service/node_modules/frisby/lib/frisby.js:1219:11) at Frisby.hence I am using after(function(err,res,body) instead of afterJSON(function(json)) even expectJSON(201) is throwing an error.
any suggestions please??